Files
Go-http_framework/vendor/github.com/ahmetb/go-linq/reverse.go
T
Huangzj dc80b557e3 feat(Go-Tool):
2020/12/16: 添加YAML和结构体转换工具
2020-12-16 14:23:38 +08:00

31 lines
712 B
Go

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
}
},
}
}