lens-3.3: Lenses, Folds and Traversals

PortabilityMTPCs, FDs, Rank2
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Inferred

Control.Lens.Action

Contents

Description

 

Synopsis

Composable Actions

type Action m s a = forall f r. Effective m r f => (a -> f a) -> s -> f sSource

An Action is a Getter enriched with access to a Monad for side-effects.

Every Getter can be used as an Action

You can compose an Action with another Action using (.) from the Prelude.

act :: Monad m => (s -> m a) -> Action m s aSource

Construct an Action from a monadic side-effect

acts :: Action m (m a) aSource

A self-running Action, analogous to join.

acts = act id
>>> (1,"hello")^!_2.acts.to succ
"ifmmp"

perform :: Monad m => Acting m a s t a b -> s -> m aSource

Perform an Action.

 perform = flip (^!)

performs :: Monad m => Acting m e s t a b -> (a -> e) -> s -> m eSource

Perform an Action and modify the result.

liftAct :: (MonadTrans trans, Monad m) => Acting m a s t a b -> Action (trans m) s aSource

Apply a Monad transformer to an Action.

(^!) :: Monad m => s -> Acting m a s t a b -> m aSource

Perform an Action

>>> ["hello","world"]^!folded.act putStrLn
hello
world

Folds with Effecs

type MonadicFold m s a = forall f r. (Effective m r f, Applicative f) => (a -> f a) -> s -> f sSource

A MonadicFold is a Fold enriched with access to a Monad for side-effects.

Every Fold can be used as a MonadicFold, that simply ignores the access to the Monad.

You can compose a MonadicFold with another MonadicFold using (.) from the Prelude.

Implementation Details

type Acting m r s t a b = (a -> Effect m r b) -> s -> Effect m r tSource

Used to evaluate an Action.