git.iko.soy/rowtype-yoga/purescript-native
on ac2b456 help sign in
42 lines 1.3 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Language.PureScript.Traversals
4-- Copyright : (c) 2014 Phil Freeman
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- | Common functions for implementing generic traversals
12--
13-----------------------------------------------------------------------------
15module Language.PureScript.Traversals where
17import Prelude ()
18import Prelude.Compat
20fstM :: (Functor f) => (a -> f c) -> (a, b) -> f (c, b)
21fstM f (a, b) = flip (,) b <$> f a
23sndM :: (Functor f) => (b -> f c) -> (a, b) -> f (a, c)
24sndM f (a, b) = (,) a <$> f b
26thirdM :: (Functor f) => (c -> f d) -> (a, b, c) -> f (a, b, d)
27thirdM f (a, b, c) = (,,) a b <$> f c
29pairM :: (Applicative f) => (a -> f c) -> (b -> f d) -> (a, b) -> f (c, d)
30pairM f g (a, b) = (,) <$> f a <*> g b
32maybeM :: (Applicative f) => (a -> f b) -> Maybe a -> f (Maybe b)
33maybeM _ Nothing = pure Nothing
34maybeM f (Just a) = Just <$> f a
36eitherM :: (Applicative f) => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d)
37eitherM f _ (Left a) = Left <$> f a
38eitherM _ g (Right b) = Right <$> g b
40defS :: (Monad m) => st -> val -> m (st, val)
41defS s val = return (s, val)