! Copyright (C) 2008 Slava Pestov
-! See http://factorcode.org/license.txt for BSD license.
-USING: arrays kernel sequences sequences.deep splitting
-accessors fry locals combinators namespaces lists lists.lazy
-shuffle ;
+! See https://factorcode.org/license.txt for BSD license.
+USING: accessors arrays kernel lists lists.lazy sequences ;
IN: monads
! Functors
-GENERIC# fmap 1 ( functor quot -- functor' )
-GENERIC# <$ 1 ( functor quot -- functor' )
-GENERIC# $> 1 ( functor quot -- functor' )
+GENERIC#: fmap 1 ( functor quot -- functor' )
+GENERIC#: <$ 1 ( functor quot -- functor' )
+GENERIC#: $> 1 ( functor quot -- functor' )
! Monads
M: list monad-of drop list-monad ;
-M: list >>= '[ _ swap lazy-map lconcat ] ;
+M: list >>= '[ _ swap lmap-lazy lconcat ] ;
! State
SINGLETON: state-monad
: 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> ;