Skip to content

Commit

Permalink
refactor: update Compose func in function.go
Browse files Browse the repository at this point in the history
  • Loading branch information
duke-git committed Dec 14, 2021
1 parent d1b74cf commit 60f3a72
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]

Expand Down
10 changes: 4 additions & 6 deletions function/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 60f3a72

Please sign in to comment.