diff --git a/walk/walk.go b/walk/walk.go index 871f1bf..acb72af 100644 --- a/walk/walk.go +++ b/walk/walk.go @@ -35,6 +35,11 @@ func Walk(x interface{}, fn func(string)) { break } } + case reflect.Func: + valFnResult := val.Call(nil) + for _, res := range valFnResult { + walkValue(res) + } } } diff --git a/walk/walk_test.go b/walk/walk_test.go index d24bf7c..40fb741 100644 --- a/walk/walk_test.go +++ b/walk/walk_test.go @@ -115,6 +115,21 @@ func TestWalk(t *testing.T) { t.Errorf("got %v want %v", got, want) } }) + + t.Run("with functions", func(t *testing.T) { + aFunction := func() (Profile, Profile) { + return Profile{21, "Berlin"}, Profile{28, "Beijing"} + } + + var got []string + want := []string{"Berlin", "Beijing"} + Walk(aFunction, func(input string) { + got = append(got, input) + }) + if !reflect.DeepEqual(got, want) { + t.Errorf("got %v want %v", got, want) + } + }) } func assertContains(t testing.TB, haystack []string, needle string) {