Skip to content

Commit 204d699

Browse files
committed
Inline validating mapper function
1 parent 0598b75 commit 204d699

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

map.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ func Map(in, out, mapperFn interface{}) error {
1414
}
1515

1616
mapper := reflect.ValueOf(mapperFn)
17-
if err := validateMapperFunction(mapper); err != nil {
18-
return err
17+
if mapper.Kind() != reflect.Func {
18+
return fmt.Errorf("mapperFn has to be a function")
19+
}
20+
21+
mapperFnType := mapper.Type()
22+
if mapperFnType.NumIn() != 1 {
23+
return fmt.Errorf("mapper function has to take only one argument")
24+
}
25+
26+
if mapperFnType.NumOut() != 1 {
27+
return fmt.Errorf("mapper function should return only one return value")
1928
}
2029

2130
if input.Kind() == reflect.Slice {
@@ -38,20 +47,3 @@ func Map(in, out, mapperFn interface{}) error {
3847
return fmt.Errorf("not implemented")
3948
}
4049

41-
42-
func validateMapperFunction(mapper reflect.Value) error {
43-
if mapper.Kind() != reflect.Func {
44-
return fmt.Errorf("mapperFn has to be a function")
45-
}
46-
47-
mapperFnType := mapper.Type()
48-
if mapperFnType.NumIn() != 1 {
49-
return fmt.Errorf("mapper function has to take only one argument")
50-
}
51-
52-
if mapperFnType.NumOut() != 1 {
53-
return fmt.Errorf("mapper function should return only one return value")
54-
}
55-
56-
return nil
57-
}

0 commit comments

Comments
 (0)