-
Notifications
You must be signed in to change notification settings - Fork 2
/
function.go2
58 lines (55 loc) · 1.52 KB
/
function.go2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package function
// Compose applies 2 functions in left to right order and applies 1 argument to the first function
//
// Parameters
//
// • fn0: unary function
// • fn1: unary function
// • data: argument to the first function
//
// Return Value
//
// • result: output value of type T2 after applying each function
//
func Compose2[A0 any, T1 any, T2 any](fn0 func(A0) T1, fn1 func(T1) T2) func(A0) T2 {
return func(data A0) T2 {
return fn1(fn0(data))
}
}
// Compose applies 3 functions in left to right order and applies 1 argument to the first function
//
// Parameters
//
// • fn0: unary function
// • fn1: unary function
// • fn2: unary function
// • data: argument to the first function
//
// Return Value
//
// • result: output value of type T3 after applying each function
//
func Compose3[A0 any, T1 any, T2 any, T3 any](fn0 func(A0) T1, fn1 func(T1) T2, fn2 func(T2) T3) func(A0) T3 {
return func(data A0) T3 {
return fn2(fn1(fn0(data)))
}
}
// Compose applies 4 functions in left to right order and applies 1 argument to the first function
//
// Parameters
//
// • fn0: unary function
// • fn1: unary function
// • fn2: unary function
// • fn3: unary function
// • data: argument to the first function
//
// Return Value
//
// • result: output value of type T4 after applying each function
//
func Compose4[A0 any, T1 any, T2 any, T3 any, T4 any](fn0 func(A0) T1, fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4) func(A0) T4 {
return func(data A0) T4 {
return fn3(fn2(fn1(fn0(data))))
}
}