1 USING: tools.test math kernel sequences lists promises monads ;
4 [ 5 ] [ 1 identity-monad return [ 4 + ] fmap run-identity ] unit-test
5 [ "OH HAI" identity-monad fail ] must-fail
8 111 just [ 6 * ] fmap [ ] [ "OOPS" throw ] if-maybe
12 111 just [ maybe-monad fail ] bind
16 5 either-monad return [ 10 * ] [ 20 * ] if-either
19 [ T{ left f "OOPS" } ] [
20 5 either-monad return >>= [ drop "OOPS" either-monad fail ] swap call
24 { 1 2 3 } [ 10 * ] fmap
28 { 1 2 3 } [ drop "OOPS" array-monad fail ] bind
32 5 state-monad return "initial state" run-st
36 5 state-monad return [ 3 + state-monad return ] bind
37 "initial state" run-st
41 5 state-monad return >>=
42 [ 3 + state-monad return ] swap call
43 "initial state" run-st
47 f state-monad return >>=
48 [ drop get-st ] swap call
73 [ " bye" append just ]
79 LAZY: nats-from ( n -- list )
80 dup 1+ nats-from cons ;
87 [ dup 3 = [ list-monad return ] [ list-monad fail ] if ]
100 [ 3 + reader-monad return ]
106 f reader-monad return [ drop ask ] bind [ 1 + ] local 5 run-reader
110 5 writer-monad return
111 [ drop { 1 2 3 } tell ] bind
115 [ T{ identity f 7 } ]
117 4 identity-monad return
118 [ 3 + ] identity-monad return
123 5 just nothing maybe-monad apply
127 5 just [ 10 + ] just maybe-monad apply