@@ -9,18 +9,8 @@ import (
99func Map (in , out , mapperFn interface {}) error {
1010 input := reflect .ValueOf (in )
1111 output := reflect .ValueOf (out )
12-
13- zeroValue := reflect.Value {}
14- if output == zeroValue {
15- return fmt .Errorf ("output is nil. Pass a reference to set output" )
16- }
17-
18- if output .IsNil () {
19- return fmt .Errorf ("output is nil. Pass a reference to set output" )
20- }
21-
22- if ! output .Elem ().CanSet () {
23- return fmt .Errorf ("cannot set out. Pass a reference to set output" )
12+ if err := validateMapperOut (output ); err != nil {
13+ return err
2414 }
2515
2616 mapper := reflect .ValueOf (mapperFn )
@@ -48,6 +38,23 @@ func Map(in, out, mapperFn interface{}) error {
4838 return fmt .Errorf ("not implemented" )
4939}
5040
41+ func validateMapperOut (output reflect.Value ) error {
42+ zeroValue := reflect.Value {}
43+ if output == zeroValue {
44+ return fmt .Errorf ("output is nil. Pass a reference to set output" )
45+ }
46+
47+ if output .IsNil () {
48+ return fmt .Errorf ("output is nil. Pass a reference to set output" )
49+ }
50+
51+ if ! output .Elem ().CanSet () {
52+ return fmt .Errorf ("cannot set out. Pass a reference to set output" )
53+ }
54+
55+ return nil
56+ }
57+
5158func validateMapperFunction (mapper reflect.Value ) error {
5259 if mapper .Kind () != reflect .Func {
5360 return fmt .Errorf ("mapperFn has to be a function" )
0 commit comments