From 60f3a72c885d9a031796956dadb7ac839923e25f Mon Sep 17 00:00:00 2001 From: dudaodong Date: Tue, 14 Dec 2021 10:29:53 +0800 Subject: [PATCH] refactor: update Compose func in function.go --- function/function.go | 4 ++-- function/function_test.go | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/function/function.go b/function/function.go index 7112f3e..1ece80e 100644 --- a/function/function.go +++ b/function/function.go @@ -48,8 +48,8 @@ func (f Fn) Curry(i interface{}) func(...interface{}) interface{} { } // Compose compose the functions from right to left -func Compose(fnList ...func(...string) string) func(...string) string { - return func(s... string) string { +func Compose(fnList ...func(...interface{}) interface{}) func(...interface{}) interface{} { + return func(s... interface{}) interface{} { f := fnList[0] restFn := fnList[1:] diff --git a/function/function_test.go b/function/function_test.go index c934249..bed16d0 100644 --- a/function/function_test.go +++ b/function/function_test.go @@ -71,19 +71,17 @@ func TestCurry(t *testing.T) { } func TestCompose(t *testing.T) { - toUpper := func(a... string) string { - return strings.ToUpper(a[0]) + toUpper := func(a ...interface{}) interface{} { + return strings.ToUpper(a[0].(string)) } - - toLower := func(a... string) string { - return strings.ToLower(a[0]) + toLower := func(a ...interface{}) interface{} { + return strings.ToLower(a[0].(string)) } expect := toUpper(toLower("aBCde")) cf := Compose(toUpper, toLower) res := cf("aBCde") - fmt.Println(res, expect) if res != expect { t.FailNow() }