Guest User

Untitled

a guest
Mar 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. subscribeWithLast :: forall a b eff.
  2. (b -> a -> Eff (frp :: FRP | eff) b)
  3. -> b
  4. -> Event a
  5. -> Eff (frp :: FRP | eff) (Eff (frp :: FRP | eff) b)
  6. subscribeWithLast f z evt = dropRefEff $ do
  7. r <- newRef z
  8. unsub <-
  9. FRP.subscribe evt
  10. (\e -> readRef r >>= \a -> addRefEff (f a e) >>= writeRef r)
  11. pure (dropRefEff (unsub *> readRef r))
  12. where
  13. dropRefEff :: forall e x. Eff (ref :: REF | e) x -> Eff e x
  14. dropRefEff = unsafeCoerceEff
  15. addRefEff :: forall e x. Eff e x -> Eff (ref :: REF | e) x
  16. addRefEff = unsafeCoerceEff
  17. --
Add Comment
Please, Sign In to add comment