feat(Go-Tool):2020/12/14:添加validator.v8源码解析和使用示例
This commit is contained in:
+4
-47
@@ -19,33 +19,11 @@ func (q Query) Where(predicate func(interface{}) bool) Query {
|
||||
}
|
||||
}
|
||||
|
||||
// WhereT is the typed version of Where.
|
||||
// WhereIndexed filters a collection of values based on a predicate.
|
||||
// Each element's index is used in the logic of the predicate function.
|
||||
//
|
||||
// - predicateFn is of type "func(TSource)bool"
|
||||
//
|
||||
// NOTE: Where has better performance than WhereT.
|
||||
func (q Query) WhereT(predicateFn interface{}) Query {
|
||||
|
||||
predicateGenericFunc, err := newGenericFunc(
|
||||
"WhereT", "predicateFn", predicateFn,
|
||||
simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
predicateFunc := func(item interface{}) bool {
|
||||
return predicateGenericFunc.Call(item).(bool)
|
||||
}
|
||||
|
||||
return q.Where(predicateFunc)
|
||||
}
|
||||
|
||||
// WhereIndexed filters a collection of values based on a predicate. Each
|
||||
// element's index is used in the logic of the predicate function.
|
||||
//
|
||||
// The first argument represents the zero-based index of the element within
|
||||
// collection. The second argument of predicate represents the element to test.
|
||||
// The first argument represents the zero-based index of the element within collection.
|
||||
// The second argument of predicate represents the element to test.
|
||||
func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query {
|
||||
return Query{
|
||||
Iterate: func() Iterator {
|
||||
@@ -66,24 +44,3 @@ func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// WhereIndexedT is the typed version of WhereIndexed.
|
||||
//
|
||||
// - predicateFn is of type "func(int,TSource)bool"
|
||||
//
|
||||
// NOTE: WhereIndexed has better performance than WhereIndexedT.
|
||||
func (q Query) WhereIndexedT(predicateFn interface{}) Query {
|
||||
predicateGenericFunc, err := newGenericFunc(
|
||||
"WhereIndexedT", "predicateFn", predicateFn,
|
||||
simpleParamValidator(newElemTypeSlice(new(int), new(genericType)), newElemTypeSlice(new(bool))),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
predicateFunc := func(index int, item interface{}) bool {
|
||||
return predicateGenericFunc.Call(index, item).(bool)
|
||||
}
|
||||
|
||||
return q.WhereIndexed(predicateFunc)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user