feat(Go-Tool):

2020/12/16: 添加YAML和结构体转换工具
This commit is contained in:
Huangzj
2020-12-16 14:23:38 +08:00
parent 61966551cd
commit dc80b557e3
32 changed files with 1700 additions and 324 deletions
+28 -8
View File
@@ -2,8 +2,8 @@ package linq
// Intersect produces the set intersection of the source collection and the
// provided input collection. The intersection of two sets A and B is defined as
// the set that contains all the elements of A that also appear in B,
// but no other elements.
// the set that contains all the elements of A that also appear in B, but no
// other elements.
func (q Query) Intersect(q2 Query) Query {
return Query{
Iterate: func() Iterator {
@@ -31,14 +31,12 @@ func (q Query) Intersect(q2 Query) Query {
// IntersectBy produces the set intersection of the source collection and the
// provided input collection. The intersection of two sets A and B is defined as
// the set that contains all the elements of A that also appear in B,
// but no other elements.
// the set that contains all the elements of A that also appear in B, but no
// other elements.
//
// IntersectBy invokes a transform function on each element of both collections.
func (q Query) IntersectBy(
q2 Query,
selector func(interface{}) interface{},
) Query {
func (q Query) IntersectBy(q2 Query,
selector func(interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
@@ -65,3 +63,25 @@ func (q Query) IntersectBy(
},
}
}
// IntersectByT is the typed version of IntersectBy.
//
// - selectorFn is of type "func(TSource) TSource"
//
// NOTE: IntersectBy has better performance than IntersectByT.
func (q Query) IntersectByT(q2 Query,
selectorFn interface{}) Query {
selectorGenericFunc, err := newGenericFunc(
"IntersectByT", "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.IntersectBy(q2, selectorFunc)
}