lens-indexed-plated-0.1.0: Indexed version of Plated.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Lens.IndexedPlated

Description

An indexed version of Plated.

This module provides a similar API to lens' Plated, with the following key differences:

  • all corresponding functions from Plated have a i prefix, similarly to what lens does (see over and iover for instance);
  • all Getter, Setter and LensLike are replaced by their Indexed equivalents, and all take an additional index parameter
Synopsis

Indexed plated

class IndexedPlated i a where Source #

Methods

iplate :: i -> IndexedTraversal' i a a Source #

IndexedTraversal of the immediate children of this structure.

Children

ichildren :: IndexedPlated i a => i -> a -> [(i, a)] Source #

Given an IndexedPlated container and its index, extract the immediate descendants of the container and their indices.

Since: 0.1.0

Rewrite

irewrite :: IndexedPlated i a => (i -> a -> Maybe a) -> i -> a -> a Source #

Rewrite a container by applying a rule everywhere possible. If the rule returns Nothing, the value remains unchanged, but while it returns a new value the transformation will be recursively applied. This guarantees that this function is applied everywhere possible, and that the result does not contain any eligible value.

Since: 0.1.0

irewriteOf :: (i -> IndexedSetter i a b a b) -> (i -> b -> Maybe a) -> i -> a -> b Source #

Rewrite a container by applying a rule everywhere possible, using the provided lens to locate immediate children. If the rule returns Nothing, the value remains unchanged, but while it returns a new value the transformation will be recursively applied. This guarantees that this function is applied everywhere possible, and that the result does not contain any eligible value.

Since: 0.1.0

irewriteOn :: IndexedPlated i a => ASetter s t a a -> (i -> a -> Maybe a) -> i -> s -> t Source #

Similar to irewrite, but performed recursively over part of a larger structure.

Since: 0.1.0

irewriteOnOf :: ASetter s t a b -> (i -> IndexedSetter i a b a b) -> (i -> b -> Maybe a) -> i -> s -> t Source #

Similar to irewriteOf, but performed recursively over part of a larger structure.

Since: 0.1.0

irewriteM :: (Monad m, IndexedPlated i a) => (i -> a -> m (Maybe a)) -> i -> a -> m a Source #

Similar to irewrite, but using a monadic rule.

Since: 0.1.0

irewriteMOf :: Monad m => (i -> IndexedLensLike i (WrappedMonad m) a b a b) -> (i -> b -> m (Maybe a)) -> i -> a -> m b Source #

Similar to irewriteOf, but using a monadic rule.

Since: 0.1.0

irewriteMOn :: (Monad m, IndexedPlated i a) => LensLike (WrappedMonad m) s t a a -> (i -> a -> m (Maybe a)) -> i -> s -> m t Source #

Similar to irewriteOn, but using a monadic rule.

Since: 0.1.0

irewriteMOnOf :: Monad m => LensLike (WrappedMonad m) s t a b -> (i -> IndexedLensLike i (WrappedMonad m) a b a b) -> (i -> b -> m (Maybe a)) -> i -> s -> m t Source #

Similar to irewriteOnOf, but using a monadic rule.

Since: 0.1.0

Universe

iuniverse :: forall i a. IndexedPlated i a => i -> a -> [(i, a)] Source #

Retrieve all of the transitive descendants (and their indices) of an IndexedPlated container, including itself.

Since: 0.1.0

iuniverseOf :: (i -> IndexedGetting i (Endo [(i, a)]) a a) -> i -> a -> [(i, a)] Source #

Retrieve all of the transitive descendants (and their indices) of a container, including itself, using the provided lens to locate immediate children.

Since: 0.1.0

iuniverseOn :: IndexedPlated i a => Getting (Endo [(i, a)]) s a -> i -> s -> [(i, a)] Source #

Similar to iuniverse, but performed recursively over part of a larger structure.

Since: 0.1.0

iuniverseOnOf :: Getting (Endo [(i, a)]) s a -> (i -> IndexedGetting i (Endo [(i, a)]) a a) -> i -> s -> [(i, a)] Source #

Similar to iuniverseOf, but performed recursively over part of a larger structure.

Since: 0.1.0

Cosmos

icosmos :: IndexedPlated i a => i -> IndexedFold i a a Source #

Fold over all transitive descendants (and their indices) of an IndexedPlated container, including itself.

Since: 0.1.0

icosmosOf :: (Applicative f, Contravariant f) => (i -> IndexedLensLike' i f a a) -> i -> IndexedLensLike' i f a a Source #

Fold over all transitive descendants (and their indices) of a container, including itself, using the provided lens to locate immediate children.

Since: 0.1.0

icosmosOn :: (Applicative f, Contravariant f, IndexedPlated i a) => LensLike' f s a -> i -> LensLike' f s a Source #

Similar to icosmos, but performed recursively over part of a larger structure.

Since: 0.1.0

icosmosOnOf :: (Applicative f, Contravariant f) => LensLike' f s a -> (i -> IndexedLensLike' i f a a) -> i -> LensLike' f s a Source #

Similar to icosmosOf, but performed recursively over part of a larger structure.

Since: 0.1.0

Transform

itransform :: IndexedPlated i a => (i -> a -> a) -> i -> a -> a Source #

Recursively transform every element in the structure, in a bottom-up manner.

Since: 0.1.0

itransformOf :: (i -> IndexedSetter i a b a b) -> (i -> b -> b) -> i -> a -> b Source #

Recursively transform every element in the structure, in a bottom-up manner, using the provided lens to locate immediate children.

Since: 0.1.0

itransformOn :: IndexedPlated i a => ASetter s t a a -> (i -> a -> a) -> i -> s -> t Source #

Similar to itransform, but performed recursively over part of a larger structure.

Since: 0.1.0

itransformOnOf :: ASetter s t a b -> (i -> IndexedSetter i a b a b) -> (i -> b -> b) -> i -> s -> t Source #

Similar to itransformOf, but performed recursively over part of a larger structure.

Since: 0.1.0

itransformM :: (Monad m, IndexedPlated i a) => (i -> a -> m a) -> i -> a -> m a Source #

Similar to itransform, but using a monadic rule.

Since: 0.1.0

itransformMOf :: Monad m => (i -> IndexedLensLike i (WrappedMonad m) a b a b) -> (i -> b -> m b) -> i -> a -> m b Source #

Similar to itransformOf, but using a monadic rule.

Since: 0.1.0

itransformMOn :: (Monad m, IndexedPlated i a) => LensLike (WrappedMonad m) s t a a -> (i -> a -> m a) -> i -> s -> m t Source #

Similar to itransformOn, but using a monadic rule.

Since: 0.1.0

itransformMOnOf :: Monad m => LensLike (WrappedMonad m) s t a b -> (i -> IndexedLensLike i (WrappedMonad m) a b a b) -> (i -> b -> m b) -> i -> s -> m t Source #

Similar to itransformOnOf, but using a monadic rule.

Since: 0.1.0

Paramorphisms

ipara :: IndexedPlated i a => (i -> a -> [r] -> r) -> i -> a -> r Source #

Perform a fold-like computation on each value within a container.

Since: 0.1.0

iparaOf :: (i -> IndexedGetting i (Endo [(i, a)]) a a) -> (i -> a -> [r] -> r) -> i -> a -> r Source #

Perform a fold-like computation on each value within a container, using the provided lens to locate immediate children.

Since: 0.1.0