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
+8 -41
View File
@@ -6,11 +6,14 @@ type Group struct {
Group []interface{}
}
// GroupBy method groups the elements of a collection according to a specified
// key selector function and projects the elements for each group by using a
// specified function.
func (q Query) GroupBy(keySelector func(interface{}) interface{},
elementSelector func(interface{}) interface{}) Query {
// GroupBy method groups the elements of a collection according
// to a specified key selector function and projects the elements for each group
// by using a specified function.
func (q Query) GroupBy(
keySelector func(interface{}) interface{},
elementSelector func(interface{}) interface{},
) Query {
return Query{
func() Iterator {
next := q.Iterate()
@@ -43,39 +46,3 @@ func (q Query) GroupBy(keySelector func(interface{}) interface{},
},
}
}
// GroupByT is the typed version of GroupBy.
//
// - keySelectorFn is of type "func(TSource) TKey"
// - elementSelectorFn is of type "func(TSource) TElement"
//
// NOTE: GroupBy has better performance than GroupByT.
func (q Query) GroupByT(keySelectorFn interface{},
elementSelectorFn interface{}) Query {
keySelectorGenericFunc, err := newGenericFunc(
"GroupByT", "keySelectorFn", keySelectorFn,
simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
)
if err != nil {
panic(err)
}
keySelectorFunc := func(item interface{}) interface{} {
return keySelectorGenericFunc.Call(item)
}
elementSelectorGenericFunc, err := newGenericFunc(
"GroupByT", "elementSelectorFn", elementSelectorFn,
simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
)
if err != nil {
panic(err)
}
elementSelectorFunc := func(item interface{}) interface{} {
return elementSelectorGenericFunc.Call(item)
}
return q.GroupBy(keySelectorFunc, elementSelectorFunc)
}