[Haskell-cafe] Data.Functor.Compose Combinator
Ben Kolera
ben.kolera at gmail.com
Wed Mar 20 06:45:57 UTC 2019
Hi,
I was wondering if this function exists somewhere (i'm not attached to the
name):
(<<$>>) :: (Functor f) => (a -> g b) -> f a -> Compose f g b
(<<$>>) mkG = Compose . fmap mkG
It's handy if you're working with an applicative (e.g Reflex.Dynamic) and
want to layer on top a validation type function that returns a different
applicative that need composing. So I figure that it must exist somewhere!
:)
E.g.
data Person = Person Text Email
nameTextDyn :: Dynamic t Text
emailTextDyn :: Dynamic t Text
validEmail :: Text -> Validation (NonEmpty Text) Email
validPersonDyn :: Dynamic t (Validation (NonEmpty Text) Person =
getCompose $ Person
<$> (pure <<$>> name)
<*> (validEmail <<$>> emailTextDyn)
Cheers,
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190320/9256a61c/attachment-0001.html>
More information about the Haskell-Cafe
mailing list