-- | Common functions for implementing generic traversals
module Language.PureScript.Traversals where

import Prelude

sndM :: (Functor f) => (b -> f c) -> (a, b) -> f (a, c)
sndM :: forall (f :: * -> *) b c a.
Functor f =>
(b -> f c) -> (a, b) -> f (a, c)
sndM b -> f c
f (a
a, b
b) = (a
a, ) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f c
f b
b

sndM' :: (Functor f) => (a -> b -> f c) -> (a, b) -> f (a, c)
sndM' :: forall (f :: * -> *) a b c.
Functor f =>
(a -> b -> f c) -> (a, b) -> f (a, c)
sndM' a -> b -> f c
f (a
a, b
b) = (a
a, ) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> b -> f c
f a
a b
b

thirdM :: (Functor f) => (c -> f d) -> (a, b, c) -> f (a, b, d)
thirdM :: forall (f :: * -> *) c d a b.
Functor f =>
(c -> f d) -> (a, b, c) -> f (a, b, d)
thirdM c -> f d
f (a
a, b
b, c
c) = (a
a, b
b, ) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f d
f c
c

pairM :: (Applicative f) => (a -> f c) -> (b -> f d) -> (a, b) -> f (c, d)
pairM :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> (a, b) -> f (c, d)
pairM a -> f c
f b -> f d
g (a
a, b
b)  = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f c
f a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> f d
g b
b

eitherM :: (Applicative f) => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d)
eitherM :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Either a b -> f (Either c d)
eitherM a -> f c
f b -> f d
_ (Left a
a)  = forall a b. a -> Either a b
Left  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f c
f a
a
eitherM a -> f c
_ b -> f d
g (Right b
b) = forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f d
g b
b

defS :: (Monad m) => st -> val -> m (st, val)
defS :: forall (m :: * -> *) st val. Monad m => st -> val -> m (st, val)
defS st
s val
val = forall (m :: * -> *) a. Monad m => a -> m a
return (st
s, val
val)