feat(Go-Tool):2020/11/23:修改项目案例(按照一定规则对一组数据进行排序分组)

This commit is contained in:
Huangzj
2020-11-23 11:00:36 +08:00
parent 179e5f6a31
commit 333d7a5d66
47 changed files with 2851 additions and 1469 deletions
+40
View File
@@ -0,0 +1,40 @@
package linq
// Union produces the set union of two collections.
//
// This method excludes duplicates from the return set. This is different
// behavior to the Concat method, which returns all the elements in the input
// collection including duplicates.
func (q Query) Union(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
set := make(map[interface{}]bool)
use1 := true
return func() (item interface{}, ok bool) {
if use1 {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
use1 = false
}
for item, ok = next2(); ok; item, ok = next2() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
return
}
},
}
}