lens-3.7.0.2: Lenses, Folds and Traversals

Portabilityrank 2 types, MPTCs, TFs, flexible
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellTrustworthy

Control.Lens.IndexedSetter

Contents

Description

 

Synopsis

Indexed Setter

type IndexedSetter i s t a b = forall f k. (Indexable i k, Settable f) => k (a -> f b) (s -> f t)Source

Every IndexedSetter is a valid Setter

The Setter laws are still required to hold.

imapOf :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> tSource

Map with index.

When you do not need access to the index, then mapOf is more liberal in what it can accept.

mapOf l ≡ imapOf l . const
 imapOf :: IndexedSetter i s t a b    -> (i -> a -> b) -> s -> t
 imapOf :: IndexedLens i s t a b      -> (i -> a -> b) -> s -> t
 imapOf :: IndexedTraversal i s t a b -> (i -> a -> b) -> s -> t

iover :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> tSource

Map with index. This is an alias for imapOf.

When you do not need access to the index, then over is more liberal in what it can accept.

over l ≡ iover l . const
 iover :: IndexedSetter i s t a b    -> (i -> a -> b) -> s -> t
 iover :: IndexedLens i s t a b      -> (i -> a -> b) -> s -> t
 iover :: IndexedTraversal i s t a b -> (i -> a -> b) -> s -> t

isets :: ((i -> a -> b) -> s -> t) -> IndexedSetter i s t a bSource

Build an IndexedSetter from an imap-like function.

Your supplied function f is required to satisfy:

 f idid
 f g . f h ≡ f (g . h)

Equational reasoning:

 isets . ioverid
 iover . isetsid

Another way to view sets is that it takes a "semantic editor combinator" and transforms it into a Setter.

(%@~) :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> tSource

Adjust every target of an IndexedSetter, IndexedLens or IndexedTraversal with access to the index.

(%@~) ≡ imapOf

When you do not need access to the index then (%@~) is more liberal in what it can accept.

l %~ f ≡ l %@~ const f
 (%@~) :: IndexedSetter i s t a b    -> (i -> a -> b) -> s -> t
 (%@~) :: IndexedLens i s t a b      -> (i -> a -> b) -> s -> t
 (%@~) :: IndexedTraversal i s t a b -> (i -> a -> b) -> s -> t

(%@=) :: MonadState s m => Overloaded (Indexed i) Mutator s s a b -> (i -> a -> b) -> m ()Source

Adjust every target in the current state of an IndexedSetter, IndexedLens or IndexedTraversal with access to the index.

When you do not need access to the index then (%=) is more liberal in what it can accept.

l %= f ≡ l %@= const f
 (%@=) :: MonadState s m => IndexedSetter i s s a b    -> (i -> a -> b) -> m ()
 (%@=) :: MonadState s m => IndexedLens i s s a b      -> (i -> a -> b) -> m ()
 (%@=) :: MonadState s m => IndexedTraversal i s t a b -> (i -> a -> b) -> m ()

Storing Indexed Setters

newtype ReifiedIndexedSetter i s t a b Source

Useful for storage.

Constructors

ReifyIndexedSetter 

Fields

reflectIndexedSetter :: IndexedSetter i s t a b
 

Simple