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
+32 -12
View File
@@ -1,19 +1,17 @@
package linq
// Zip applies a specified function to the corresponding elements
// of two collections, producing a collection of the results.
// Zip applies a specified function to the corresponding elements of two
// collections, producing a collection of the results.
//
// The method steps through the two input collections, applying function
// resultSelector to corresponding elements of the two collections.
// The method returns a collection of the values that are returned by resultSelector.
// If the input collections do not have the same number of elements,
// the method combines elements until it reaches the end of one of the collections.
// For example, if one collection has three elements and the other one has four,
// the result collection has only three elements.
func (q Query) Zip(
q2 Query,
resultSelector func(interface{}, interface{}) interface{},
) Query {
// resultSelector to corresponding elements of the two collections. The method
// returns a collection of the values that are returned by resultSelector. If
// the input collections do not have the same number of elements, the method
// combines elements until it reaches the end of one of the collections. For
// example, if one collection has three elements and the other one has four, the
// result collection has only three elements.
func (q Query) Zip(q2 Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
@@ -33,3 +31,25 @@ func (q Query) Zip(
},
}
}
// ZipT is the typed version of Zip.
//
// - resultSelectorFn is of type "func(TFirst,TSecond)TResult"
//
// NOTE: Zip has better performance than ZipT.
func (q Query) ZipT(q2 Query,
resultSelectorFn interface{}) Query {
resultSelectorGenericFunc, err := newGenericFunc(
"ZipT", "resultSelectorFn", resultSelectorFn,
simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
)
if err != nil {
panic(err)
}
resultSelectorFunc := func(item1 interface{}, item2 interface{}) interface{} {
return resultSelectorGenericFunc.Call(item1, item2)
}
return q.Zip(q2, resultSelectorFunc)
}