swarm-0.5.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Swarm.Util.Effect

Description

fused-effect utilities for Swarm.

Synopsis

Documentation

withThrow :: Has (Throw e2) sig m => (e1 -> e2) -> ThrowC e1 m a -> m a Source #

Transform a Throw e1 constraint into a Throw e2 constraint, by supplying an adapter function of type (e1 -> e2).

throwToMaybe :: forall e m a. Functor m => ThrowC e m a -> m (Maybe a) Source #

Transform a Throw e constrint into a concrete Maybe, discarding the error.

throwToWarning :: Has (Accum (Seq e)) sig m => ThrowC e m a -> m (Maybe a) Source #

Transform a Throw e constrint into a concrete Maybe, logging any error as a warning.

ignoreWarnings :: forall e m a. (Monoid e, Functor m) => AccumC e m a -> m a Source #

Run a computation with an Accum effect (typically accumulating a list of warnings), ignoring the accumulated value.

asExceptT :: ThrowC e m a -> ExceptT e m a Source #

Convert a fused-effects style computation using a Throw e constraint into an ExceptT computation. This is mostly a stub to convert from one style to the other while we are in the middle of incrementally converting. Eventually this should not be needed.

warn :: Has (Accum (Seq w)) sig m => w -> m () Source #

Log a single failure as a warning.

traverseW :: (Has (Accum (Seq w)) sig m, Witherable t) => (a -> m (Either w b)) -> t a -> m (t b) Source #

A version of traverse/mapM that also accumulates warnings.

Note that we can't generalize this to work over any Traversable because it also needs to have a notion of "filtering". Witherable provides exactly the right abstraction.

forMW :: (Has (Accum (Seq w)) sig m, Witherable t) => t a -> (a -> m (Either w b)) -> m (t b) Source #

Flipped version of traverseW for convenience.