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
+30
View File
@@ -0,0 +1,30 @@
package linq
// Reverse inverts the order of the elements in a collection.
//
// Unlike OrderBy, this sorting method does not consider the actual values
// themselves in determining the order. Rather, it just returns the elements in
// the reverse order from which they are produced by the underlying source.
func (q Query) Reverse() Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
items := []interface{}{}
for item, ok := next(); ok; item, ok = next() {
items = append(items, item)
}
index := len(items) - 1
return func() (item interface{}, ok bool) {
if index < 0 {
return
}
item, ok = items[index], true
index--
return
}
},
}
}