Created
March 21, 2014 11:46
-
-
Save rehno-lindeque/9684480 to your computer and use it in GitHub Desktop.
Elm Functor/Applicative operator shorthands
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
-- Shorthand map over List-like | |
f <$ lx = map f lx -- <$> in Haskell | |
lx $> f = map f lx | |
infixr 2 <$ | |
infixr 2 $> | |
-- Shorthand sequential application | |
lf <$$ lx = zipWith (\f x -> f x) lf lx -- <*> in Haskell | |
lx $$> lf = zipWith (\f x -> f x) lf lx -- <**> in Haskell | |
infixr 1 <$$ | |
infixr 1 $$> | |
--Shorthand map over Maybe | |
f <? mx = case mx of -- <$> in Haskell | |
(Just x) -> Just (f x) | |
Nothing -> Nothing | |
mx ?> f = case mx of | |
Just x -> Just (f x) | |
Nothing -> Nothing | |
infixr 2 <? | |
infixr 2 ?> | |
-- Shorthand sequential application | |
mf <?? mx = if isJust mx && isJust mf -- <*> in Haskell | |
then Just <| (\(Just f) (Just x) -> f x) mf mx | |
else Nothing | |
mx ??> mf = if isJust mx && isJust mf -- <**> in Haskell | |
then Just <| (\(Just f) (Just x) -> f x) mf mx | |
else Nothing | |
infixr 1 <?? | |
infixr 1 ??> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment