代码拉取完成,页面将自动刷新
package linq
// Distinct method returns distinct elements from a collection.
// The result is an unordered collection that contains no duplicate values.
func (q Query) Distinct() Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
return
}
},
}
}
// Distinct method returns distinct elements from a collection.
// The result is an ordered collection that contains no duplicate values.
//
// NOTE: Distinct method on OrderedQuery type has better performance than
// Distinct method on Query type
func (oq OrderedQuery) Distinct() OrderedQuery {
return OrderedQuery{
orders: oq.orders,
Query: Query{
Iterate: func() Iterator {
next := oq.Iterate()
var prev interface{}
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if item != prev {
prev = item
return
}
}
return
}
},
},
}
}
// DistinctBy method returns distinct elements from a collection. This method
// executes selector function for each element to determine a value to compare.
// The result is an unordered collection that contains no duplicate values.
func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
s := selector(item)
if _, has := set[s]; !has {
set[s] = true
return
}
}
return
}
},
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。