Created
March 13, 2018 17:24
-
-
Save eric-corumdigital/60746399669e6321b3850735860b8302 to your computer and use it in GitHub Desktop.
purescript-behaviors subscribeWithLast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subscribeWithLast :: forall a b eff. | |
(b -> a -> Eff (frp :: FRP | eff) b) | |
-> b | |
-> Event a | |
-> Eff (frp :: FRP | eff) (Eff (frp :: FRP | eff) b) | |
subscribeWithLast f z evt = dropRefEff $ do | |
r <- newRef z | |
unsub <- | |
FRP.subscribe evt | |
(\e -> readRef r >>= \a -> addRefEff (f a e) >>= writeRef r) | |
pure (dropRefEff (unsub *> readRef r)) | |
where | |
dropRefEff :: forall e x. Eff (ref :: REF | e) x -> Eff e x | |
dropRefEff = unsafeCoerceEff | |
addRefEff :: forall e x. Eff e x -> Eff (ref :: REF | e) x | |
addRefEff = unsafeCoerceEff | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment