-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmonadIO_test.go
More file actions
42 lines (36 loc) · 823 Bytes
/
monadIO_test.go
File metadata and controls
42 lines (36 loc) · 823 Bytes
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
package fpgo
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMonadIO(t *testing.T) {
var m *MonadIODef[interface{}]
var actualInt int
m = MonadIO.Just(1)
actualInt = 0
m.Subscribe(Subscription[interface{}]{
OnNext: func(in interface{}) {
actualInt, _ = Maybe.Just(in).ToInt()
},
})
assert.Equal(t, 1, actualInt)
m = MonadIO.Just(1).FlatMap(func(in interface{}) *MonadIODef[interface{}] {
v, _ := Maybe.Just(in).ToInt()
return MonadIO.Just(v + 1)
})
actualInt = 0
m.Subscribe(Subscription[interface{}]{
OnNext: func(in interface{}) {
actualInt, _ = Maybe.Just(in).ToInt()
},
})
assert.Equal(t, 2, actualInt)
actualInt = 0
m = MonadIO.New(func() interface{} {
actualInt = 3
return 0
})
assert.Equal(t, 0, actualInt)
m.Eval()
assert.Equal(t, 3, actualInt)
}