-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpgo_test.go
86 lines (81 loc) · 1.65 KB
/
fpgo_test.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package fpgo_test
import (
"fmt"
"strconv"
"strings"
"testing"
"github.com/p9595jh/fpgo"
)
func TestPipe(t *testing.T) {
v := fpgo.Pipe[[]int, *int](
[]int{1, 3, 2, 4, 5},
fpgo.Sort(func(i1, i2 *int) bool {
return *i1 > *i2
}),
fpgo.Map(func(_ int, t *int) *string {
s := fmt.Sprintf("abc%d", *t)
return &s
}),
fpgo.Slice[string](1, 4),
fpgo.Reverse[string](),
fpgo.Reduce(func(i int, s1, s2 *string) *string {
s := fmt.Sprintf("%s %s", *s1, *s2)
return &s
}),
fpgo.Func(func(s *string) []string {
*s = strings.Trim(*s, " ")
return strings.Split(*s, " ")
}),
fpgo.Map(func(_ int, t *string) *int {
i, _ := strconv.ParseInt((*t)[3:], 10, 32)
i2 := int(i)
return &i2
}),
fpgo.Reduce(func(i int, t *int, u *int) *int {
*u += *t
return u
}),
)
t.Log(*v)
}
func TestProcessing(t *testing.T) {
res := fpgo.ProcessingPipe[[]int, []int](
[]int{5, 4, 1, 3, 2},
[2]fpgo.A{
func(a any) {
t.Log(a)
},
},
fpgo.Sort(func(t1, t2 *int) bool {
return *t1 < *t2
}),
fpgo.Reverse[int](),
fpgo.At[int](2),
fpgo.MapOne(func(i *int) *[]int {
return &[]int{*i}
}),
fpgo.Append([]int{10, 20}),
)
t.Log(res)
}
func TestChain(t *testing.T) {
s := fpgo.New([]int{2, 4, 1, 5, 3}).
F(fpgo.Append([]int{10, 11})).
F(fpgo.Reverse[int]()).
F(fpgo.Map(func(i1 int, i2 *int) *int {
*i2 += i1
return i2
})).
F(fpgo.Filter(func(i1 int, i2 *int) bool {
return i1%2 == 1
})).
F(fpgo.ForEach(func(i1 int, i2 *int, i3 []int) {
t.Log(*i2)
})).
F(fpgo.At[int](-1)).
F(fpgo.MapOne(func(i *int) *string {
s := fmt.Sprintf("*%d*", *i)
return &s
})).V.(string)
t.Log(s)
}