Skip to content

Instantly share code, notes, and snippets.

@bluescreen303
Created April 3, 2012 20:49
Show Gist options
  • Save bluescreen303/2295402 to your computer and use it in GitHub Desktop.
Save bluescreen303/2295402 to your computer and use it in GitHub Desktop.
event-depending behaviors
once :: Event t a -> Event t a
once e = let b = stepper True (False <$ e)
in whenE b e
changes' :: Eq a => Event t (a, a) -> Event t a
changes' e = fst <$> filterE (uncurry (/=)) e
stepperP :: a -> Event t a -> (Event t (a, a), Behavior t a)
stepperP acc e = mapAccum acc (withPrev <$> e)
where withPrev x acc = ((x, acc), x)
stepperC :: Eq a => a -> Event t a -> (Event t a, Behavior t a)
stepperC acc e = let (e', b) = stepperP acc e
in (changes e', b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment