-USING: tools.test math kernel sequences lists promises monads ;
+USING: tools.test math math.functions kernel sequences lists
+promises monads ;
FROM: monads => do ;
IN: monads.tests
run-writer
] unit-test
+{
+ T{ writer
+ { value 1.618033988749895 }
+ { log
+ "Started with five, took square root, added one, divided by two."
+ }
+ }
+} [
+ {
+ [ 5 "Started with five, " <writer> ]
+ [ sqrt "took square root, " <writer> ]
+ [ 1 + "added one, " <writer> ]
+ [ 2 / "divided by two." <writer> ]
+ } do
+] unit-test
+
{ T{ identity f 7 } }
[
4 identity-monad return
: run-writer ( writer -- value log ) [ value>> ] [ log>> ] bi ;
-M: writer >>= '[ [ _ run-writer ] dip '[ @ run-writer ] dip append <writer> ] ;
+M: writer >>= '[ [ _ run-writer ] dip '[ @ run-writer ] dip prepend <writer> ] ;
: pass ( writer -- writer' ) run-writer [ first2 ] dip swap call( x -- y ) <writer> ;
: listen ( writer -- writer' ) run-writer [ 2array ] keep <writer> ;