Skip to content

Commit

Permalink
Switch coroutine monad to Affable
Browse files Browse the repository at this point in the history
  • Loading branch information
beckyconning committed Aug 25, 2016
1 parent af4895a commit fbcfc47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"purescript-control": "^1.0.0",
"purescript-foreign": "^1.1.0",
"purescript-freet": "^1.0.0",
"purescript-generics": "^1.0.1"
"purescript-generics": "^1.0.1",
"purescript-aff-free": "^1.0.0"
},
"devDependencies": {
"purescript-test-unit": "^9.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/Control/Coroutine/Aff/Seq.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import Control.Coroutine.Aff (produceAff)
import Control.Monad.Aff (Aff)
import Control.Monad.Aff.AVar (AVAR)
import Control.Monad.Free.Trans (hoistFreeT)
import Control.Monad.Aff.Class (class MonadAff, liftAff)
import Control.Monad.Aff.Free (class Affable, fromAff)
import Data.Either (Either(..))
import Data.Functor (($>))
import Prelude

type AffGetter a b eff = b -> Aff (avar :: AVAR | eff) a

produceSeq :: forall a b m eff. (MonadAff (avar :: AVAR | eff) m) => AffGetter a b eff -> (a -> b) -> b -> Producer a m Unit
produceSeq :: forall a b m eff. (Affable (avar :: AVAR | eff) m, Functor m) => AffGetter a b eff -> (a -> b) -> b -> Producer a m Unit
produceSeq get pluckSeq initialSeq = produceAff' \emit -> getNext emit initialSeq
where
getNext emit seq = get seq >>= emitAndGetNext emit
emitAndGetNext emit x = (emit $ Left x) *> getNext emit (pluckSeq x)

produceAff'
:: forall a r m eff
. (MonadAff (avar :: AVAR | eff) m)
. (Affable (avar :: AVAR | eff) m, Functor m)
=> ((Either a r -> Aff (avar :: AVAR | eff) Unit) -> Aff (avar :: AVAR | eff) Unit)
-> Producer a m r
produceAff' = hoistFreeT liftAff <<< produceAff
produceAff' = hoistFreeT fromAff <<< produceAff

0 comments on commit fbcfc47

Please sign in to comment.