-
-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Copyright 2021 [email protected]. All rights reserved. | ||
// Use of this source code is governed by MIT license | ||
|
||
// Package function implements some functions for functional programming. | ||
// Package function implements some functions for control the function execution and some is for functional programming. | ||
|
||
package function | ||
|
||
|
@@ -47,7 +47,22 @@ func (f Fn) Curry(i interface{}) func(...interface{}) interface{} { | |
} | ||
} | ||
|
||
// Delay make the function excution after delayed time | ||
// Compose compose the functions from right to left | ||
func Compose(fnList ...func(...string) string) func(...string) string { | ||
return func(s... string) string { | ||
f := fnList[0] | ||
restFn := fnList[1:] | ||
|
||
if len(fnList) == 1 { | ||
return f(s...) | ||
} | ||
|
||
return f(Compose(restFn...)(s...)) | ||
} | ||
} | ||
|
||
|
||
// Delay make the function execution after delayed time | ||
func Delay(delay time.Duration, fn interface{}, args ...interface{}) { | ||
time.Sleep(delay) | ||
invokeFunc(fn, args...) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters