git.iko.soy/rowtype-yoga/purescript-native
on a628008 help sign in
27 lines 922 B history raw
1-- | Common functions for implementing generic traversals
2module Language.PureScript.Traversals where
4import Prelude.Compat
6fstM :: (Functor f) => (a -> f c) -> (a, b) -> f (c, b)
7fstM f (a, b) = flip (,) b <$> f a
9sndM :: (Functor f) => (b -> f c) -> (a, b) -> f (a, c)
10sndM f (a, b) = (,) a <$> f b
12thirdM :: (Functor f) => (c -> f d) -> (a, b, c) -> f (a, b, d)
13thirdM f (a, b, c) = (,,) a b <$> f c
15pairM :: (Applicative f) => (a -> f c) -> (b -> f d) -> (a, b) -> f (c, d)
16pairM f g (a, b) = (,) <$> f a <*> g b
18maybeM :: (Applicative f) => (a -> f b) -> Maybe a -> f (Maybe b)
19maybeM _ Nothing = pure Nothing
20maybeM f (Just a) = Just <$> f a
22eitherM :: (Applicative f) => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d)
23eitherM f _ (Left a) = Left <$> f a
24eitherM _ g (Right b) = Right <$> g b
26defS :: (Monad m) => st -> val -> m (st, val)
27defS s val = return (s, val)