git.iko.soy/rowtype-yoga/purescript-native
on 98eaa39 help sign in
34 lines 999 B 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 Control.Applicative
19fstM :: (Functor f) => (a -> f c) -> (a, b) -> f (c, b)
20fstM f (a, b) = flip (,) b <$> f a
22sndM :: (Functor f) => (b -> f c) -> (a, b) -> f (a, c)
23sndM f (a, b) = (,) a <$> f b
25thirdM :: (Functor f) => (c -> f d) -> (a, b, c) -> f (a, b, d)
26thirdM f (a, b, c) = (,,) a b <$> f c
28maybeM :: (Applicative f) => (a -> f b) -> Maybe a -> f (Maybe b)
29maybeM _ Nothing = pure Nothing
30maybeM f (Just a) = Just <$> f a
32defS :: (Monad m) => st -> val -> m (st, val)
33defS s val = return (s, val)