-- |

module Test.Sandwich.Util where

import Control.Monad

whenLeft :: (Monad m) => Either a b -> (a -> m ()) -> m ()
whenLeft :: Either a b -> (a -> m ()) -> m ()
whenLeft (Left a
x) a -> m ()
action = a -> m ()
action a
x
whenLeft (Right b
_) a -> m ()
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

whenJust :: (Monad m) => Maybe a -> (a -> m b) -> m ()
whenJust :: Maybe a -> (a -> m b) -> m ()
whenJust Maybe a
Nothing a -> m b
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
whenJust (Just a
x) a -> m b
action = m b -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m b -> m ()) -> m b -> m ()
forall a b. (a -> b) -> a -> b
$ a -> m b
action a
x