Skip to content

Instantly share code, notes, and snippets.

@JBetz
Last active January 28, 2019 15:17
Show Gist options
  • Save JBetz/c5e677e5676246d61d503ea025952b12 to your computer and use it in GitHub Desktop.
Save JBetz/c5e677e5676246d61d503ea025952b12 to your computer and use it in GitHub Desktop.
dynamic that only updates when constructor changes
renderEither :: Dynamic t (Either a b) -> m ()
renderEither eitherD = do
uniqEitherD <- holdUniqDynBy (\x y -> isRight x && isRight y || isLeft x && isLeft y) eitherD
dyn_ $ ffor uniqEitherD $ \case
Left val -> renderLeft $ fromLeft val <$> eitherD
Right val -> renderRight $ fromRight val <$> eitherD
renderLeft :: Dynamic t a -> m ()
renderRight :: Dynamic t b -> m ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment