Karya, built on Mon Jul 24 11:39:07 PDT 2017 (patch 33511aca01257b76b88de7c7a2763b7a965c084e)

Safe HaskellNone

Util.Control

Contents

Description

Control flow and monadic utilities.

Synopsis

Documentation

class Bifunctor p where Source #

This is like the hackage bifunctor package, but with no extra dependencies, and no clowns.

Minimal complete definition

(***), first, second

Methods

(***) :: (a -> b) -> (c -> d) -> p a c -> p b d infixr 3 Source #

first :: (a -> b) -> p a c -> p b c Source #

second :: (c -> d) -> p a c -> p a d Source #

Instances

Bifunctor Either # 

Methods

(***) :: (a -> b) -> (c -> d) -> Either a c -> Either b d Source #

first :: (a -> b) -> Either a c -> Either b c Source #

second :: (c -> d) -> Either a c -> Either a d Source #

Bifunctor (,) # 

Methods

(***) :: (a -> b) -> (c -> d) -> (a, c) -> (b, d) Source #

first :: (a -> b) -> (a, c) -> (b, c) Source #

second :: (c -> d) -> (a, c) -> (a, d) Source #

while :: Monad.Monad m => m Bool -> m a -> m [a] Source #

while_ :: Monad.Monad m => m Bool -> m a -> m () Source #

mconcatMap :: Monoid b => (a -> b) -> [a] -> b Source #

This is foldMap specialized to lists.

concatMapM :: (Monad.Monad m, Monoid b) => (a -> m b) -> [a] -> m b Source #

This is actually a mconcatMapM.

A further generalized version would be:

foldMapA :: (Applicative f, Traversable t, Monoid m) =>
   (a -> f m) -> t a -> f m
foldMapA f = fmap Foldable.fold . traverse f

justm :: Monad.Monad m => m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b) Source #

Run the second action only if the first action returns Just.

This is like MaybeT, but using MaybeT itself required lots of annoying explicit lifting.

rightm :: Monad.Monad m => m (Either err a) -> (a -> m (Either err b)) -> m (Either err b) Source #

The Either equivalent of justm. EitherT solves the same problem, but requires a runEitherT and lots of hoistEithers.

firstJust :: Monad.Monad m => m (Maybe a) -> m (Maybe a) -> m (Maybe a) Source #

Return the first action to return Just.

firstJusts :: Monad.Monad m => [m (Maybe a)] -> m (Maybe a) Source #

firstJust applied to a list.

errors

justErr :: err -> Maybe a -> Either err a Source #

Throw on Nothing.

tryJust :: MonadError e m => e -> Maybe a -> m a Source #

I usually call this require.

tryRight :: MonadError e m => Either e a -> m a Source #

I usually call this require_right.