feat(Go-Tool):2020/12/14:添加validator.v8源码解析和使用示例

This commit is contained in:
Huangzj
2020-12-14 15:15:58 +08:00
parent 23d7d6e226
commit fa31b23cca
51 changed files with 4619 additions and 1662 deletions
+5 -28
View File
@@ -1,7 +1,7 @@
package linq
// Distinct method returns distinct elements from a collection. The result is an
// unordered collection that contains no duplicate values.
// 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 {
@@ -22,11 +22,11 @@ func (q Query) Distinct() Query {
}
}
// Distinct method returns distinct elements from a collection. The result is an
// ordered collection that contains no duplicate values.
// 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.
// Distinct method on Query type
func (oq OrderedQuery) Distinct() OrderedQuery {
return OrderedQuery{
orders: oq.orders,
@@ -73,26 +73,3 @@ func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {
},
}
}
// DistinctByT is the typed version of DistinctBy.
//
// - selectorFn is of type "func(TSource) TSource".
//
// NOTE: DistinctBy has better performance than DistinctByT.
func (q Query) DistinctByT(selectorFn interface{}) Query {
selectorFunc, ok := selectorFn.(func(interface{}) interface{})
if !ok {
selectorGenericFunc, err := newGenericFunc(
"DistinctByT", "selectorFn", selectorFn,
simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
)
if err != nil {
panic(err)
}
selectorFunc = func(item interface{}) interface{} {
return selectorGenericFunc.Call(item)
}
}
return q.DistinctBy(selectorFunc)
}