mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-11 00:02:28 +08:00
test: add some unit test function for convertor, random, slice, and formatter
This commit is contained in:
@@ -137,17 +137,16 @@ func Map(slice, function interface{}) interface{} {
|
||||
// The function signature should be func(index int, value1, value2 interface{}) interface{} .
|
||||
func Reduce(slice, function, zero interface{}) interface{} {
|
||||
sv := sliceValue(slice)
|
||||
elementType := sv.Type().Elem()
|
||||
|
||||
len := sv.Len()
|
||||
if len == 0 {
|
||||
return zero
|
||||
} else if len == 1 {
|
||||
return sv.Index(0)
|
||||
return sv.Index(0).Interface()
|
||||
}
|
||||
|
||||
elementType := sv.Type().Elem()
|
||||
fn := functionValue(function)
|
||||
|
||||
if checkSliceCallbackFuncSignature(fn, elementType, elementType, elementType) {
|
||||
t := elementType.String()
|
||||
panic("Reduce function must be of type func(int, " + t + ", " + t + ")" + t)
|
||||
|
||||
Reference in New Issue
Block a user