HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelens-5.3.5Haskell2010

Control.Lens.Operators

This module exists for users who like to work with qualified imports but want access to the operators from Lens.

import qualified Control.Lens as L
import Control.Lens.Operators
  • 140 values
  • Packagelens-5.3.5
  • Exports140
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceOperators.hs

Control.Lens.Cons

14 declarations
value(<|) :: Cons s s a a => a -> s -> s
#

cons an element onto a container.

This is an infix alias for cons.

Example1 expression
a <| [][a]
Example1 expression
a <| [b, c][a,b,c]
Example1 expression
a <| Seq.fromList []fromList [a]
Example1 expression
a <| Seq.fromList [b, c]fromList [a,b,c]
value(|>) :: Snoc s s a a => s -> a -> s
#

snoc an element onto a container.

This is an infix alias for snoc.

Example1 expression
Seq.fromList [] |> afromList [a]
Example1 expression
Seq.fromList [b, c] |> afromList [b,c,a]
Example1 expression
LazyT.pack "hello" |> '!'"hello!"
value(<|~) :: Cons b b a a => ASetter s t b b -> a -> s -> t
#

Modify the target(s) of a Lens', Iso, Setter or Traversal using (<|).

Example1 expression
(["world"], ["lens"]) & _1 <|~ "hello"(["hello","world"],["lens"])
value(<<|~) :: Cons b b a a => LensLike (Tuple2 b) s t b b -> a -> s -> (b, t)
#

(<|) a value onto the target of a Lens and return the result.

When you do not need the result of the operation, (<|~) is more flexible.

value(<<|=)
  1. :: (MonadState s m, Cons b b a a)
  2. => LensLike (Tuple2 b) s s b b
  3. -> a
  4. -> m b
#

(<|) a value onto the target of a Lens into your Monad's state and return the result.

When you do not need the result of the operation, (<|=) is more flexible.

value(<<<|~) :: Cons b b a a => LensLike' (Tuple2 b) s b -> a -> s -> (b, s)
#

(<|) a value onto the target of a Lens and return the old result.

When you do not need the result of the operation, (<|~) is more flexible.

value(<<<|=)
  1. :: (MonadState s m, Cons b b a a)
  2. => LensLike (Tuple2 b) s s b b
  3. -> a
  4. -> m b
#

(<|) a value onto the target of a Lens into your Monad's state and return the old result.

When you do not need the result of the operation, (<|=) is more flexible.

value(|>~) :: Snoc b b a a => ASetter s t b b -> a -> s -> t
#

Modify the target(s) of a Lens', Iso, Setter or Traversal using (|>).

Example1 expression
(["world"], ["lens"]) & _1 |>~ "hello"(["world","hello"],["lens"])
value(<|>~) :: Snoc b b p p => LensLike (Tuple2 b) s t b b -> p -> s -> (b, t)
#

(|>) a value onto the target of a Lens and return the result.

When you do not need the result of the operation, (|>~) is more flexible.

value(<|>=)
  1. :: (MonadState s m, Snoc b b p p)
  2. => LensLike (Tuple2 b) s s b b
  3. -> p
  4. -> m b
#

(|>) a value onto the target of a Lens into your Monad's state and return the result.

When you do not need the result of the operation, (|>=) is more flexible.

value(<<|>~) :: Snoc b b p p => LensLike' (Tuple2 b) s b -> p -> s -> (b, s)
#

(|>) a value onto the target of a Lens and return the old result.

When you do not need the result of the operation, (|>~) is more flexible.

value(<<|>=)
  1. :: (MonadState s m, Snoc b b p p)
  2. => LensLike (Tuple2 b) s s b b
  3. -> p
  4. -> m b
#

(|>) a value onto the target of a Lens into your Monad's state and return the old result.

When you do not need the result of the operation, (|>=) is more flexible.

Control.Lens.Fold

6 declarations
value(^?) :: s -> Getting (First a) s a -> Maybe a
#

Perform a safe head of a Fold or Traversal or retrieve Just the result from a Getter or Lens.

When using a Traversal as a partial Lens, or a Fold as a partial Getter this can be a convenient way to extract the optional value.

Note: if you get stack overflows due to this, you may want to use firstOf instead, which can deal more gracefully with heavily left-biased trees. This is because ^? works by using the First monoid, which can occasionally cause space leaks.

Example1 expression
Left 4 ^?_LeftJust 4
Example1 expression
Right 4 ^?_LeftNothing
Example1 expression
"world" ^? ix 3Just 'l'
Example1 expression
"world" ^? ix 20Nothing

This operator works as an infix version of preview.

(^?) ≡ flip preview

It may be helpful to think of ^? as having one of the following more specialized types:

(^?) :: s -> Getter s a     -> Maybe a
(^?) :: s -> Fold s a       -> Maybe a
(^?) :: s -> Lens' s a      -> Maybe a
(^?) :: s -> Iso' s a       -> Maybe a
(^?) :: s -> Traversal' s a -> Maybe a
value(^@?) :: s -> IndexedGetting i (Endo (Maybe (i, a))) s a -> Maybe (i, a)
#

Perform a safe head (with index) of an IndexedFold or IndexedTraversal or retrieve Just the index and result from an IndexedGetter or IndexedLens.

When using a IndexedTraversal as a partial IndexedLens, or an IndexedFold as a partial IndexedGetter this can be a convenient way to extract the optional value.

(^@?) :: s -> IndexedGetter i s a     -> Maybe (i, a)
(^@?) :: s -> IndexedFold i s a       -> Maybe (i, a)
(^@?) :: s -> IndexedLens' i s a      -> Maybe (i, a)
(^@?) :: s -> IndexedTraversal' i s a -> Maybe (i, a)

Control.Lens.Getter

2 declarations
value(^.) :: s -> Getting a s a -> a
#

View the value pointed to by a Getter or Lens or the result of folding over all the results of a Control.Lens.Fold.Fold or Control.Lens.Traversal.Traversal that points at a monoidal values.

This is the same operation as view with the arguments flipped.

The fixity and semantics are such that subsequent field accesses can be performed with (Prelude..).

Example1 expression
(a,b)^._2b
Example1 expression
("hello","world")^._2"world"
Example2 expressions
import Data.Complex((0, 1 :+ 2), 3)^._1._2.to magnitude2.23606797749979
(^.) ::             s -> Getter s a     -> a
(^.) :: Monoid m => s -> Control.Lens.Fold.Fold s m       -> m
(^.) ::             s -> Control.Lens.Iso.Iso' s a       -> a
(^.) ::             s -> Lens' s a      -> a
(^.) :: Monoid m => s -> Control.Lens.Traversal.Traversal' s m -> m
value(^@.) :: s -> IndexedGetting i (i, a) s a -> (i, a)
#

View the index and value of an IndexedGetter or IndexedLens.

This is the same operation as iview with the arguments flipped.

The fixity and semantics are such that subsequent field accesses can be performed with (Prelude..).

(^@.) :: s -> IndexedGetter i s a -> (i, a)
(^@.) :: s -> IndexedLens' i s a  -> (i, a)

The result probably doesn't have much meaning when applied to an IndexedFold.

Control.Lens.Indexed

3 declarations
value(<.)
  1. :: Indexable i p
  2. => Indexed i s t -> r
  3. -> (a -> b) -> s -> t
  4. -> p a b
  5. -> r
#

Compose an Indexed function with a non-indexed function.

Mnemonically, the < points to the indexing we want to preserve.

Example2 expressions
let nestedMap = (fmap Map.fromList . Map.fromList) [(1, [(10, "one,ten"), (20, "one,twenty")]), (2, [(30, "two,thirty"), (40,"two,forty")])]nestedMap^..(itraversed<.itraversed).withIndex[(1,"one,ten"),(1,"one,twenty"),(2,"two,thirty"),(2,"two,forty")]
value(.>) :: (st -> r) -> (kab -> st) -> kab -> r
#

Compose a non-indexed function with an Indexed function.

Mnemonically, the > points to the indexing we want to preserve.

This is the same as (.).

f . g (and f .> g) gives you the index of g unless g is index-preserving, like a Prism, Iso or Equality, in which case it'll pass through the index of f.

Example2 expressions
let nestedMap = (fmap Map.fromList . Map.fromList) [(1, [(10, "one,ten"), (20, "one,twenty")]), (2, [(30, "two,thirty"), (40,"two,forty")])]nestedMap^..(itraversed.>itraversed).withIndex[(10,"one,ten"),(20,"one,twenty"),(30,"two,thirty"),(40,"two,forty")]
value(<.>)
  1. :: Indexable (i, j) p
  2. => Indexed i s t -> r
  3. -> Indexed j a b -> s -> t
  4. -> p a b
  5. -> r
#

Composition of Indexed functions.

Mnemonically, the < and > points to the fact that we want to preserve the indices.

Example2 expressions
let nestedMap = (fmap Map.fromList . Map.fromList) [(1, [(10, "one,ten"), (20, "one,twenty")]), (2, [(30, "two,thirty"), (40,"two,forty")])]nestedMap^..(itraversed<.>itraversed).withIndex[((1,10),"one,ten"),((1,20),"one,twenty"),((2,30),"two,thirty"),((2,40),"two,forty")]

Control.Lens.Lens

76 declarations
value(%%~) :: LensLike f s t a b -> (a -> f b) -> s -> f t
#

(%%~) can be used in one of two scenarios:

When applied to a Lens, it can edit the target of the Lens in a structure, extracting a functorial result.

When applied to a Traversal, it can edit the targets of the traversals, extracting an applicative summary of its actions.

Example1 expression
[66,97,116,109,97,110] & each %%~ \a -> ("na", chr a)("nananananana","Batman")

For all that the definition of this combinator is just:

(%%~) ≡ id

It may be beneficial to think about it as if it had these even more restricted types, however:

(%%~) :: Functor f =>     Control.Lens.Iso.Iso s t a b       -> (a -> f b) -> s -> f t
(%%~) :: Functor f =>     Lens s t a b      -> (a -> f b) -> s -> f t
(%%~) :: Applicative f => Traversal s t a b -> (a -> f b) -> s -> f t

When applied to a Traversal, it can edit the targets of the traversals, extracting a supplemental monoidal summary of its actions, by choosing f = ((,) m)

(%%~) ::             Control.Lens.Iso.Iso s t a b       -> (a -> (r, b)) -> s -> (r, t)
(%%~) ::             Lens s t a b      -> (a -> (r, b)) -> s -> (r, t)
(%%~) :: Monoid m => Traversal s t a b -> (a -> (m, b)) -> s -> (m, t)
value(%%=) :: MonadState s m => Over p (Tuple2 r) s s a b -> p a (r, b) -> m r
#

Modify the target of a Lens in the current state returning some extra information of type r or modify all targets of a Control.Lens.Traversal.Traversal in the current state, extracting extra information of type r and return a monoidal summary of the changes.

Example1 expression
runState (_1 %%= \x -> (f x, g x)) (a,b)(f a,(g a,b))
(%%=) ≡ (state .)

It may be useful to think of (%%=), instead, as having either of the following more restricted type signatures:

(%%=) :: MonadState s m             => Control.Lens.Iso.Iso s s a b       -> (a -> (r, b)) -> m r
(%%=) :: MonadState s m             => Lens s s a b      -> (a -> (r, b)) -> m r
(%%=) :: (MonadState s m, Monoid r) => Control.Lens.Traversal.Traversal s s a b -> (a -> (r, b)) -> m r
value(&) :: a -> (a -> b) -> b
#

& is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator $, which allows & to be nested in $.

This is a version of flip id, where id is specialized from a -> a to (a -> b) -> (a -> b) which by the associativity of (->) is (a -> b) -> a -> b. flipping this yields a -> (a -> b) -> b which is the type signature of &

Examples
Example1 expression
5 & (+1) & show"6"
Example1 expression
sqrt $ [1 / n^2 | n <- [1..1000]] & sum & (*6)3.1406380562059946
value(&~) :: s -> State s a -> s
#

This can be used to chain lens operations using op= syntax rather than op~ syntax for simple non-type-changing cases.

Example1 expression
(10,20) & _1 .~ 30 & _2 .~ 40(30,40)
Example1 expression
(10,20) &~ do _1 .= 30; _2 .= 40(30,40)

This does not support type-changing assignment, e.g.

Example1 expression
(10,20) & _1 .~ "hello"("hello",20)
value(<&>) :: Functor f => f a -> (a -> b) -> f b
#

Flipped version of <$>.

(<&>) = flip fmap
Examples

Apply (+1) to a list, a Just and a Right:

Example1 expression
Just 2 <&> (+1)Just 3
Example1 expression
[1,2,3] <&> (+1)[2,3,4]
Example1 expression
Right 3 <&> (+1)Right 4
value(??) :: Functor f => f (a -> b) -> a -> f b
#

This is convenient to flip argument order of composite functions defined as:

fab ?? a = fmap ($ a) fab

For the Functor instance f = ((->) r) you can reason about this function as if the definition was (??) ≡ flip:

Example1 expression
(h ?? x) ah a x
Example1 expression
execState ?? [] $ modify (1:)[1]
Example1 expression
over _2 ?? ("hello","world") $ length("hello",5)
Example1 expression
over ?? length ?? ("hello","world") $ _2("hello",5)
value(<%~) :: LensLike (Tuple2 b) s t a b -> (a -> b) -> s -> (b, t)
#

Modify the target of a Lens and return the result.

When you do not need the result of the operation, (%~) is more flexible.

(<%~) ::             Lens s t a b      -> (a -> b) -> s -> (b, t)
(<%~) ::             Control.Lens.Iso.Iso s t a b       -> (a -> b) -> s -> (b, t)
(<%~) :: Monoid b => Control.Lens.Traversal.Traversal s t a b -> (a -> b) -> s -> (b, t)
value(<+~) :: Num a => LensLike (Tuple2 a) s t a a -> a -> s -> (a, t)
#

Increment the target of a numerically valued Lens and return the result.

When you do not need the result of the addition, (+~) is more flexible.

(<+~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<+~) :: Num a => Control.Lens.Iso.Iso' s a  -> a -> s -> (a, s)
value(<-~) :: Num a => LensLike (Tuple2 a) s t a a -> a -> s -> (a, t)
#

Decrement the target of a numerically valued Lens and return the result.

When you do not need the result of the subtraction, (-~) is more flexible.

(<-~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<-~) :: Num a => Control.Lens.Iso.Iso' s a  -> a -> s -> (a, s)
value(<*~) :: Num a => LensLike (Tuple2 a) s t a a -> a -> s -> (a, t)
#

Multiply the target of a numerically valued Lens and return the result.

When you do not need the result of the multiplication, (*~) is more flexible.

(<*~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<*~) :: Num a => Control.Lens.Iso.Iso'  s a -> a -> s -> (a, s)
value(<//~) :: Fractional a => LensLike (Tuple2 a) s t a a -> a -> s -> (a, t)
#

Divide the target of a fractionally valued Lens and return the result.

When you do not need the result of the division, (//~) is more flexible.

(<//~) :: Fractional a => Lens' s a -> a -> s -> (a, s)
(<//~) :: Fractional a => Control.Lens.Iso.Iso'  s a -> a -> s -> (a, s)
value(<^~)
  1. :: (Num a, Integral e)
  2. => LensLike (Tuple2 a) s t a a
  3. -> e
  4. -> s
  5. -> (a, t)
#

Raise the target of a numerically valued Lens to a non-negative Integral power and return the result.

When you do not need the result of the operation, (^~) is more flexible.

(<^~) :: (Num a, Integral e) => Lens' s a -> e -> s -> (a, s)
(<^~) :: (Num a, Integral e) => Control.Lens.Iso.Iso' s a -> e -> s -> (a, s)
value(<**~) :: Floating a => LensLike (Tuple2 a) s t a a -> a -> s -> (a, t)
#

Raise the target of a floating-point valued Lens to an arbitrary power and return the result.

When you do not need the result of the operation, (**~) is more flexible.

(<**~) :: Floating a => Lens' s a -> a -> s -> (a, s)
(<**~) :: Floating a => Control.Lens.Iso.Iso' s a  -> a -> s -> (a, s)
value(<<%~) :: LensLike (Tuple2 a) s t a b -> (a -> b) -> s -> (a, t)
#

Modify the target of a Lens, but return the old value.

When you do not need the old value, (%~) is more flexible.

(<<%~) ::             Lens s t a b      -> (a -> b) -> s -> (a, t)
(<<%~) ::             Control.Lens.Iso.Iso s t a b       -> (a -> b) -> s -> (a, t)
(<<%~) :: Monoid a => Control.Lens.Traversal.Traversal s t a b -> (a -> b) -> s -> (a, t)
value(<<.~) :: LensLike (Tuple2 a) s t a b -> b -> s -> (a, t)
#

Replace the target of a Lens, but return the old value.

When you do not need the old value, (.~) is more flexible.

(<<.~) ::             Lens s t a b      -> b -> s -> (a, t)
(<<.~) ::             Control.Lens.Iso.Iso s t a b       -> b -> s -> (a, t)
(<<.~) :: Monoid a => Control.Lens.Traversal.Traversal s t a b -> b -> s -> (a, t)
value(<<?~) :: LensLike (Tuple2 a) s t a (Maybe b) -> b -> s -> (a, t)
#

Replace the target of a Lens with a Just value, but return the old value.

If you do not need the old value (?~) is more flexible.

Example2 expressions
import qualified Data.Map as Map_2.at "hello" <<?~ "world" $ (42,Map.fromList [("goodnight","gracie")])(Nothing,(42,fromList [("goodnight","gracie"),("hello","world")]))
(<<?~) :: Iso s t a (Maybe b)       -> b -> s -> (a, t)
(<<?~) :: Lens s t a (Maybe b)      -> b -> s -> (a, t)
(<<?~) :: Traversal s t a (Maybe b) -> b -> s -> (a, t)
value(<<+~) :: Num a => LensLike' (Tuple2 a) s a -> a -> s -> (a, s)
#

Increment the target of a numerically valued Lens and return the old value.

When you do not need the old value, (+~) is more flexible.

Example1 expression
(a,b) & _1 <<+~ c(a,(a + c,b))
Example1 expression
(a,b) & _2 <<+~ c(b,(a,b + c))
(<<+~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<<+~) :: Num a => Iso' s a -> a -> s -> (a, s)
value(<<-~) :: Num a => LensLike' (Tuple2 a) s a -> a -> s -> (a, s)
#

Decrement the target of a numerically valued Lens and return the old value.

When you do not need the old value, (-~) is more flexible.

Example1 expression
(a,b) & _1 <<-~ c(a,(a - c,b))
Example1 expression
(a,b) & _2 <<-~ c(b,(a,b - c))
(<<-~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<<-~) :: Num a => Iso' s a -> a -> s -> (a, s)
value(<<*~) :: Num a => LensLike' (Tuple2 a) s a -> a -> s -> (a, s)
#

Multiply the target of a numerically valued Lens and return the old value.

When you do not need the old value, (-~) is more flexible.

Example1 expression
(a,b) & _1 <<*~ c(a,(a * c,b))
Example1 expression
(a,b) & _2 <<*~ c(b,(a,b * c))
(<<*~) :: Num a => Lens' s a -> a -> s -> (a, s)
(<<*~) :: Num a => Iso' s a -> a -> s -> (a, s)
value(<<//~) :: Fractional a => LensLike' (Tuple2 a) s a -> a -> s -> (a, s)
#

Divide the target of a numerically valued Lens and return the old value.

When you do not need the old value, (//~) is more flexible.

Example1 expression
(a,b) & _1 <<//~ c(a,(a / c,b))
Example1 expression
("Hawaii",10) & _2 <<//~ 2(10.0,("Hawaii",5.0))
(<<//~) :: Fractional a => Lens' s a -> a -> s -> (a, s)
(<<//~) :: Fractional a => Iso' s a -> a -> s -> (a, s)
value(<<**~) :: Floating a => LensLike' (Tuple2 a) s a -> a -> s -> (a, s)
#

Raise the target of a floating-point valued Lens to an arbitrary power and return the old value.

When you do not need the old value, (**~) is more flexible.

Example1 expression
(a,b) & _1 <<**~ c(a,(a**c,b))
Example1 expression
(a,b) & _2 <<**~ c(b,(a,b**c))
(<<**~) :: Floating a => Lens' s a -> a -> s -> (a, s)
(<<**~) :: Floating a => Iso' s a -> a -> s -> (a, s)
value(<<&&~) :: LensLike' (Tuple2 Bool) s Bool -> Bool -> s -> (Bool, s)
#

Logically && the target of a Bool-valued Lens and return the old value.

When you do not need the old value, (&&~) is more flexible.

Example1 expression
(False,6) & _1 <<&&~ True(False,(False,6))
Example1 expression
("hello",True) & _2 <<&&~ False(True,("hello",False))
(<<&&~) :: Lens' s Bool -> Bool -> s -> (Bool, s)
(<<&&~) :: Iso' s Bool -> Bool -> s -> (Bool, s)
value(<<<>~) :: Semigroup r => LensLike' (Tuple2 r) s r -> r -> s -> (r, s)
#

Modify the target of a monoidally valued Lens by using (<>) a new value and return the old value.

When you do not need the old value, (<>~) is more flexible.

Example1 expression
(Sum a,b) & _1 <<<>~ Sum c(Sum {getSum = a},(Sum {getSum = a + c},b))
Example1 expression
_2 <<<>~ ", 007" $ ("James", "Bond")("Bond",("James","Bond, 007"))
(<<<>~) :: Semigroup r => Lens' s r -> r -> s -> (r, s)
(<<<>~) :: Semigroup r => Iso' s r -> r -> s -> (r, s)
value(<<<>:~) :: Semigroup m => LensLike' (Tuple2 m) s m -> m -> s -> (m, s)
#

(<>) a Semigroup value onto the front of the target of a Lens and return the old result. However, unlike (<<>~), it is prepended to the head side.

When you do not need the result of the operation, (<>:~) is more flexible.

value(<%=) :: MonadState s m => LensLike (Tuple2 b) s s a b -> (a -> b) -> m b
#

Modify the target of a Lens into your Monad's state by a user supplied function and return the result.

When applied to a Control.Lens.Traversal.Traversal, it this will return a monoidal summary of all of the intermediate results.

When you do not need the result of the operation, (%=) is more flexible.

(<%=) :: MonadState s m             => Lens' s a      -> (a -> a) -> m a
(<%=) :: MonadState s m             => Control.Lens.Iso.Iso' s a       -> (a -> a) -> m a
(<%=) :: (MonadState s m, Monoid a) => Control.Lens.Traversal.Traversal' s a -> (a -> a) -> m a
value(<+=) :: (MonadState s m, Num a) => LensLike' (Tuple2 a) s a -> a -> m a
#

Add to the target of a numerically valued Lens into your Monad's state and return the result.

When you do not need the result of the addition, (+=) is more flexible.

(<+=) :: (MonadState s m, Num a) => Lens' s a -> a -> m a
(<+=) :: (MonadState s m, Num a) => Control.Lens.Iso.Iso' s a -> a -> m a
value(<-=) :: (MonadState s m, Num a) => LensLike' (Tuple2 a) s a -> a -> m a
#

Subtract from the target of a numerically valued Lens into your Monad's state and return the result.

When you do not need the result of the subtraction, (-=) is more flexible.

(<-=) :: (MonadState s m, Num a) => Lens' s a -> a -> m a
(<-=) :: (MonadState s m, Num a) => Control.Lens.Iso.Iso' s a -> a -> m a
value(<*=) :: (MonadState s m, Num a) => LensLike' (Tuple2 a) s a -> a -> m a
#

Multiply the target of a numerically valued Lens into your Monad's state and return the result.

When you do not need the result of the multiplication, (*=) is more flexible.

(<*=) :: (MonadState s m, Num a) => Lens' s a -> a -> m a
(<*=) :: (MonadState s m, Num a) => Control.Lens.Iso.Iso' s a -> a -> m a
value(<<%=)
  1. :: (Strong p, MonadState s m)
  2. => Over p (Tuple2 a) s s a b
  3. -> p a b
  4. -> m a
#

Modify the target of a Lens into your Monad's state by a user supplied function and return the old value that was replaced.

When applied to a Control.Lens.Traversal.Traversal, this will return a monoidal summary of all of the old values present.

When you do not need the result of the operation, (%=) is more flexible.

(<<%=) :: MonadState s m             => Lens' s a      -> (a -> a) -> m a
(<<%=) :: MonadState s m             => Control.Lens.Iso.Iso' s a       -> (a -> a) -> m a
(<<%=) :: (MonadState s m, Monoid a) => Control.Lens.Traversal.Traversal' s a -> (a -> a) -> m a
(<<%=) :: MonadState s m => LensLike ((,)a) s s a b -> (a -> b) -> m a
value(<<.=) :: MonadState s m => LensLike (Tuple2 a) s s a b -> b -> m a
#

Replace the target of a Lens into your Monad's state with a user supplied value and return the old value that was replaced.

When applied to a Control.Lens.Traversal.Traversal, this will return a monoidal summary of all of the old values present.

When you do not need the result of the operation, (.=) is more flexible.

(<<.=) :: MonadState s m             => Lens' s a      -> a -> m a
(<<.=) :: MonadState s m             => Control.Lens.Iso.Iso' s a       -> a -> m a
(<<.=) :: (MonadState s m, Monoid a) => Control.Lens.Traversal.Traversal' s a -> a -> m a
value(<<?=) :: MonadState s m => LensLike (Tuple2 a) s s a (Maybe b) -> b -> m a
#

Replace the target of a Lens into your Monad's state with Just a user supplied value and return the old value that was replaced.

When applied to a Control.Lens.Traversal.Traversal, this will return a monoidal summary of all of the old values present.

When you do not need the result of the operation, (?=) is more flexible.

(<<?=) :: MonadState s m             => Lens s t a (Maybe b)      -> b -> m a
(<<?=) :: MonadState s m             => Control.Lens.Iso.Iso s t a (Maybe b)       -> b -> m a
(<<?=) :: (MonadState s m, Monoid a) => Control.Lens.Traversal.Traversal s t a (Maybe b) -> b -> m a
value(<<<>:=)
  1. :: (MonadState s m, Semigroup r)
  2. => LensLike' (Tuple2 r) s r
  3. -> r
  4. -> m r
#

(<>) a Semigroup value onto the front of the target of a Lens into your Monad's state and return the old result. However, unlike (<<<>=), it is prepended to the head side.

When you do not need the result of the operation, (<>:=) is more flexible.

value(<<~) :: MonadState s m => ALens s s a b -> m b -> m b
#

Run a monadic action, and set the target of Lens to its result.

(<<~) :: MonadState s m => Control.Lens.Iso.Iso s s a b   -> m b -> m b
(<<~) :: MonadState s m => Lens s s a b  -> m b -> m b

NB: This is limited to taking an actual Lens than admitting a Control.Lens.Traversal.Traversal because there are potential loss of state issues otherwise.

value(<<>~) :: Semigroup m => LensLike (Tuple2 m) s t m m -> m -> s -> (m, t)
#

(<>) a Semigroup value onto the end of the target of a Lens and return the result.

When you do not need the result of the operation, (<>~) is more flexible.

value(<<>:~) :: Semigroup m => LensLike (Tuple2 m) s t m m -> m -> s -> (m, t)
#

(<>) a Semigroup value onto the front of the target of a Lens and return the result. However, unlike (<<>~), it is prepended to the head side.

When you do not need the result of the operation, (<>:~) is more flexible.

value(<<>:=)
  1. :: (MonadState s m, Semigroup r)
  2. => LensLike' (Tuple2 r) s r
  3. -> r
  4. -> m r
#

(<>) a Semigroup value onto the front of the target of a Lens into your Monad's state and return the result. However, unlike (<<>=), it is prepended to the head side.

When you do not need the result of the operation, (<>:=) is more flexible.

value(<%@~)
  1. :: Over (Indexed i) (Tuple2 b) s t a b
  2. -> i -> a -> b
  3. -> s
  4. -> (b, t)
#

Adjust the target of an IndexedLens returning the intermediate result, or adjust all of the targets of an Control.Lens.Traversal.IndexedTraversal and return a monoidal summary along with the answer.

l <%~ f ≡ l <%@~ const f

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

If you do not need the intermediate result, you can use (%@~) or even (%~).

(<%@~) ::             IndexedLens i s t a b      -> (i -> a -> b) -> s -> (b, t)
(<%@~) :: Monoid b => Control.Lens.Traversal.IndexedTraversal i s t a b -> (i -> a -> b) -> s -> (b, t)
value(<<%@~)
  1. :: Over (Indexed i) (Tuple2 a) s t a b
  2. -> i -> a -> b
  3. -> s
  4. -> (a, t)
#

Adjust the target of an IndexedLens returning the old value, or adjust all of the targets of an Control.Lens.Traversal.IndexedTraversal and return a monoidal summary of the old values along with the answer.

(<<%@~) ::             IndexedLens i s t a b      -> (i -> a -> b) -> s -> (a, t)
(<<%@~) :: Monoid a => Control.Lens.Traversal.IndexedTraversal i s t a b -> (i -> a -> b) -> s -> (a, t)
value(%%@~) :: Over (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t
#

Adjust the target of an IndexedLens returning a supplementary result, or adjust all of the targets of an Control.Lens.Traversal.IndexedTraversal and return a monoidal summary of the supplementary results and the answer.

(%%@~) ≡ Control.Lens.Indexed.withIndex
(%%@~) :: Functor f => IndexedLens i s t a b      -> (i -> a -> f b) -> s -> f t
(%%@~) :: Applicative f => Control.Lens.Traversal.IndexedTraversal i s t a b -> (i -> a -> f b) -> s -> f t

In particular, it is often useful to think of this function as having one of these even more restricted type signatures:

(%%@~) ::             IndexedLens i s t a b      -> (i -> a -> (r, b)) -> s -> (r, t)
(%%@~) :: Monoid r => Control.Lens.Traversal.IndexedTraversal i s t a b -> (i -> a -> (r, b)) -> s -> (r, t)
value(%%@=)
  1. :: MonadState s m
  2. => Over (Indexed i) (Tuple2 r) s s a b
  3. -> i -> a -> (r, b)
  4. -> m r
#

Adjust the target of an IndexedLens returning a supplementary result, or adjust all of the targets of an Control.Lens.Traversal.IndexedTraversal within the current state, and return a monoidal summary of the supplementary results.

l %%@= f ≡ state (l %%@~ f)
(%%@=) :: MonadState s m                 => IndexedLens i s s a b      -> (i -> a -> (r, b)) -> s -> m r
(%%@=) :: (MonadState s m, Monoid r) => Control.Lens.Traversal.IndexedTraversal i s s a b -> (i -> a -> (r, b)) -> s -> m r
value(<%@=)
  1. :: MonadState s m
  2. => Over (Indexed i) (Tuple2 b) s s a b
  3. -> i -> a -> b
  4. -> m b
#

Adjust the target of an IndexedLens returning the intermediate result, or adjust all of the targets of an Control.Lens.Traversal.IndexedTraversal within the current state, and return a monoidal summary of the intermediate results.

(<%@=) :: MonadState s m                 => IndexedLens i s s a b      -> (i -> a -> b) -> m b
(<%@=) :: (MonadState s m, Monoid b) => Control.Lens.Traversal.IndexedTraversal i s s a b -> (i -> a -> b) -> m b
value(<<%@=)
  1. :: MonadState s m
  2. => Over (Indexed i) (Tuple2 a) s s a b
  3. -> i -> a -> b
  4. -> m a
#

Adjust the target of an IndexedLens returning the old value, or adjust all of the targets of an Control.Lens.Traversal.IndexedTraversal within the current state, and return a monoidal summary of the old values.

(<<%@=) :: MonadState s m                 => IndexedLens i s s a b      -> (i -> a -> b) -> m a
(<<%@=) :: (MonadState s m, Monoid b) => Control.Lens.Traversal.IndexedTraversal i s s a b -> (i -> a -> b) -> m a
value(^#) :: s -> ALens s t a b -> a
#

A version of (^.) that works on ALens.

Example1 expression
("hello","world")^#_2"world"
value(#~) :: ALens s t a b -> b -> s -> t
#

A version of (.~) that works on ALens.

Example1 expression
("hello","there") & _2 #~ "world"("hello","world")
value(#%~) :: ALens s t a b -> (a -> b) -> s -> t
#

A version of (%~) that works on ALens.

Example1 expression
("hello","world") & _2 #%~ length("hello",5)
value(#%%~) :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t
#

A version of (%%~) that works on ALens.

Example1 expression
("hello","world") & _2 #%%~ \x -> (length x, x ++ "!")(5,("hello","world!"))
value(<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)
#

A version of (<%~) that works on ALens.

Example1 expression
("hello","world") & _2 <#%~ length(5,("hello",5))
value(<#~) :: ALens s t a b -> b -> s -> (b, t)
#

A version of (<.~) that works on ALens.

Example1 expression
("hello","there") & _2 <#~ "world"("world",("hello","world"))

Control.Lens.Plated

1 declaration

Control.Lens.Review

1 declaration
value(#) :: AReview t b -> b -> t
#

An infix alias for review.

unto f # x ≡ f x
l # x ≡ x ^. re l

This is commonly used when using a Prism as a smart constructor.

Example1 expression
_Left # 4Left 4

But it can be used for any Prism

Example1 expression
base 16 # 123"7b"
(#) :: Iso'      s a -> a -> s
(#) :: Prism'    s a -> a -> s
(#) :: Review    s a -> a -> s
(#) :: Equality' s a -> a -> s

Control.Lens.Setter

37 declarations
value(%~) :: ASetter s t a b -> (a -> b) -> s -> t
#

Modifies the target of a Lens or all of the targets of a Setter or Traversal with a user supplied function.

This is an infix version of over.

fmap f ≡ mapped %~ f
fmapDefault f ≡ traverse %~ f
Example1 expression
(a,b,c) & _3 %~ f(a,b,f c)
Example1 expression
(a,b) & both %~ f(f a,f b)
Example1 expression
_2 %~ length $ (1,"hello")(1,5)
Example1 expression
traverse %~ f $ [a,b,c][f a,f b,f c]
Example1 expression
traverse %~ even $ [1,2,3][False,True,False]
Example1 expression
traverse.traverse %~ length $ [["hello","world"],["!!!"]][[5,5],[3]]
(%~) :: Setter s t a b    -> (a -> b) -> s -> t
(%~) :: Iso s t a b       -> (a -> b) -> s -> t
(%~) :: Lens s t a b      -> (a -> b) -> s -> t
(%~) :: Traversal s t a b -> (a -> b) -> s -> t
value(.~) :: ASetter s t a b -> b -> s -> t
#

Replace the target of a Lens or all of the targets of a Setter or Traversal with a constant value.

This is an infix version of set, provided for consistency with (.=).

f <$ a ≡ mapped .~ f $ a
Example1 expression
(a,b,c,d) & _4 .~ e(a,b,c,e)
Example1 expression
(42,"world") & _1 .~ "hello"("hello","world")
Example1 expression
(a,b) & both .~ c(c,c)
(.~) :: Setter s t a b    -> b -> s -> t
(.~) :: Iso s t a b       -> b -> s -> t
(.~) :: Lens s t a b      -> b -> s -> t
(.~) :: Traversal s t a b -> b -> s -> t
value(?~) :: ASetter s t a (Maybe b) -> b -> s -> t
#

Set the target of a Lens, Traversal or Setter to Just a value.

l ?~ t ≡ set l (Just t)
Example1 expression
Nothing & id ?~ aJust a
Example1 expression
Map.empty & at 3 ?~ xfromList [(3,x)]

?~ can be used type-changily:

Example1 expression
('a', ('b', 'c')) & _2.both ?~ 'x'('a',(Just 'x',Just 'x'))
(?~) :: Setter s t a (Maybe b)    -> b -> s -> t
(?~) :: Iso s t a (Maybe b)       -> b -> s -> t
(?~) :: Lens s t a (Maybe b)      -> b -> s -> t
(?~) :: Traversal s t a (Maybe b) -> b -> s -> t
value(<.~) :: ASetter s t a b -> b -> s -> (b, t)
#

Set with pass-through.

This is mostly present for consistency, but may be useful for chaining assignments.

If you do not need a copy of the intermediate result, then using l .~ t directly is a good idea.

Example1 expression
(a,b) & _1 <.~ c(c,(c,b))
Example1 expression
("good","morning","vietnam") & _3 <.~ "world"("world",("good","morning","world"))
Example1 expression
(42,Map.fromList [("goodnight","gracie")]) & _2.at "hello" <.~ Just "world"(Just "world",(42,fromList [("goodnight","gracie"),("hello","world")]))
(<.~) :: Setter s t a b    -> b -> s -> (b, t)
(<.~) :: Iso s t a b       -> b -> s -> (b, t)
(<.~) :: Lens s t a b      -> b -> s -> (b, t)
(<.~) :: Traversal s t a b -> b -> s -> (b, t)
value(<?~) :: ASetter s t a (Maybe b) -> b -> s -> (b, t)
#

Set to Just a value with pass-through.

This is mostly present for consistency, but may be useful for for chaining assignments.

If you do not need a copy of the intermediate result, then using l ?~ d directly is a good idea.

Example2 expressions
import qualified Data.Map as Map_2.at "hello" <?~ "world" $ (42,Map.fromList [("goodnight","gracie")])("world",(42,fromList [("goodnight","gracie"),("hello","world")]))
(<?~) :: Setter s t a (Maybe b)    -> b -> s -> (b, t)
(<?~) :: Iso s t a (Maybe b)       -> b -> s -> (b, t)
(<?~) :: Lens s t a (Maybe b)      -> b -> s -> (b, t)
(<?~) :: Traversal s t a (Maybe b) -> b -> s -> (b, t)
value(+~) :: Num a => ASetter s t a a -> a -> s -> t
#

Increment the target(s) of a numerically valued Lens, Setter or Traversal.

Example1 expression
(a,b) & _1 +~ c(a + c,b)
Example1 expression
(a,b) & both +~ c(a + c,b + c)
Example1 expression
(1,2) & _2 +~ 1(1,3)
Example1 expression
[(a,b),(c,d)] & traverse.both +~ e[(a + e,b + e),(c + e,d + e)]
(+~) :: Num a => Setter' s a    -> a -> s -> s
(+~) :: Num a => Iso' s a       -> a -> s -> s
(+~) :: Num a => Lens' s a      -> a -> s -> s
(+~) :: Num a => Traversal' s a -> a -> s -> s
value(*~) :: Num a => ASetter s t a a -> a -> s -> t
#

Multiply the target(s) of a numerically valued Lens, Iso, Setter or Traversal.

Example1 expression
(a,b) & _1 *~ c(a * c,b)
Example1 expression
(a,b) & both *~ c(a * c,b * c)
Example1 expression
(1,2) & _2 *~ 4(1,8)
Example1 expression
Just 24 & mapped *~ 2Just 48
(*~) :: Num a => Setter' s a    -> a -> s -> s
(*~) :: Num a => Iso' s a       -> a -> s -> s
(*~) :: Num a => Lens' s a      -> a -> s -> s
(*~) :: Num a => Traversal' s a -> a -> s -> s
value(-~) :: Num a => ASetter s t a a -> a -> s -> t
#

Decrement the target(s) of a numerically valued Lens, Iso, Setter or Traversal.

Example1 expression
(a,b) & _1 -~ c(a - c,b)
Example1 expression
(a,b) & both -~ c(a - c,b - c)
Example1 expression
_1 -~ 2 $ (1,2)(-1,2)
Example1 expression
mapped.mapped -~ 1 $ [[4,5],[6,7]][[3,4],[5,6]]
(-~) :: Num a => Setter' s a    -> a -> s -> s
(-~) :: Num a => Iso' s a       -> a -> s -> s
(-~) :: Num a => Lens' s a      -> a -> s -> s
(-~) :: Num a => Traversal' s a -> a -> s -> s
value(//~) :: Fractional a => ASetter s t a a -> a -> s -> t
#

Divide the target(s) of a numerically valued Lens, Iso, Setter or Traversal.

Example1 expression
(a,b) & _1 //~ c(a / c,b)
Example1 expression
(a,b) & both //~ c(a / c,b / c)
Example1 expression
("Hawaii",10) & _2 //~ 2("Hawaii",5.0)
(//~) :: Fractional a => Setter' s a    -> a -> s -> s
(//~) :: Fractional a => Iso' s a       -> a -> s -> s
(//~) :: Fractional a => Lens' s a      -> a -> s -> s
(//~) :: Fractional a => Traversal' s a -> a -> s -> s
value(**~) :: Floating a => ASetter s t a a -> a -> s -> t
#

Raise the target(s) of a floating-point valued Lens, Setter or Traversal to an arbitrary power.

Example1 expression
(a,b) & _1 **~ c(a**c,b)
Example1 expression
(a,b) & both **~ c(a**c,b**c)
Example1 expression
_2 **~ 10 $ (3,2)(3,1024.0)
(**~) :: Floating a => Setter' s a    -> a -> s -> s
(**~) :: Floating a => Iso' s a       -> a -> s -> s
(**~) :: Floating a => Lens' s a      -> a -> s -> s
(**~) :: Floating a => Traversal' s a -> a -> s -> s
value(.=) :: MonadState s m => ASetter s s a b -> b -> m ()
#

Replace the target of a Lens or all of the targets of a Setter or Traversal in our monadic state with a new value, irrespective of the old.

This is an infix version of assign.

Example1 expression
execState (do _1 .= c; _2 .= d) (a,b)(c,d)
Example1 expression
execState (both .= c) (a,b)(c,c)
(.=) :: MonadState s m => Iso' s a       -> a -> m ()
(.=) :: MonadState s m => Lens' s a      -> a -> m ()
(.=) :: MonadState s m => Traversal' s a -> a -> m ()
(.=) :: MonadState s m => Setter' s a    -> a -> m ()

It puts the state in the monad or it gets the hose again.

value(%=) :: MonadState s m => ASetter s s a b -> (a -> b) -> m ()
#

Map over the target of a Lens or all of the targets of a Setter or Traversal in our monadic state.

Example1 expression
execState (do _1 %= f;_2 %= g) (a,b)(f a,g b)
Example1 expression
execState (do both %= f) (a,b)(f a,f b)
(%=) :: MonadState s m => Iso' s a       -> (a -> a) -> m ()
(%=) :: MonadState s m => Lens' s a      -> (a -> a) -> m ()
(%=) :: MonadState s m => Traversal' s a -> (a -> a) -> m ()
(%=) :: MonadState s m => Setter' s a    -> (a -> a) -> m ()
(%=) :: MonadState s m => ASetter s s a b -> (a -> b) -> m ()
value(?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m ()
#

Replace the target of a Lens or all of the targets of a Setter or Traversal in our monadic state with Just a new value, irrespective of the old.

Example1 expression
execState (do at 1 ?= a; at 2 ?= b) Map.emptyfromList [(1,a),(2,b)]
Example1 expression
execState (do _1 ?= b; _2 ?= c) (Just a, Nothing)(Just b,Just c)
(?=) :: MonadState s m => Iso' s (Maybe a)       -> a -> m ()
(?=) :: MonadState s m => Lens' s (Maybe a)      -> a -> m ()
(?=) :: MonadState s m => Traversal' s (Maybe a) -> a -> m ()
(?=) :: MonadState s m => Setter' s (Maybe a)    -> a -> m ()
value(+=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
#

Modify the target(s) of a Lens', Iso, Setter or Traversal by adding a value.

Example:

fresh :: MonadState Int m => m Int
fresh = do
  id += 1
  use id
Example1 expression
execState (do _1 += c; _2 += d) (a,b)(a + c,b + d)
Example1 expression
execState (do _1.at 1.non 0 += 10) (Map.fromList [(2,100)],"hello")(fromList [(1,10),(2,100)],"hello")
(+=) :: (MonadState s m, Num a) => Setter' s a    -> a -> m ()
(+=) :: (MonadState s m, Num a) => Iso' s a       -> a -> m ()
(+=) :: (MonadState s m, Num a) => Lens' s a      -> a -> m ()
(+=) :: (MonadState s m, Num a) => Traversal' s a -> a -> m ()
value(//=) :: (MonadState s m, Fractional a) => ASetter' s a -> a -> m ()
#

Modify the target(s) of a Lens', Iso, Setter or Traversal by dividing by a value.

Example1 expression
execState (do _1 //= c; _2 //= d) (a,b)(a / c,b / d)
(//=) :: (MonadState s m, Fractional a) => Setter' s a    -> a -> m ()
(//=) :: (MonadState s m, Fractional a) => Iso' s a       -> a -> m ()
(//=) :: (MonadState s m, Fractional a) => Lens' s a      -> a -> m ()
(//=) :: (MonadState s m, Fractional a) => Traversal' s a -> a -> m ()
value(**=) :: (MonadState s m, Floating a) => ASetter' s a -> a -> m ()
#

Raise the target(s) of a numerically valued Lens, Setter or Traversal to an arbitrary power

Example1 expression
execState (do _1 **= c; _2 **= d) (a,b)(a**c,b**d)
(**=) ::  (MonadState s m, Floating a) => Setter' s a    -> a -> m ()
(**=) ::  (MonadState s m, Floating a) => Iso' s a       -> a -> m ()
(**=) ::  (MonadState s m, Floating a) => Lens' s a      -> a -> m ()
(**=) ::  (MonadState s m, Floating a) => Traversal' s a -> a -> m ()
value(&&=) :: MonadState s m => ASetter' s Bool -> Bool -> m ()
#

Modify the target(s) of a Lens', Iso, Setter or Traversal by taking their logical && with a value.

Example1 expression
execState (do _1 &&= True; _2 &&= False; _3 &&= True; _4 &&= False) (True,True,False,False)(True,False,False,False)
(&&=) :: MonadState s m => Setter' s Bool    -> Bool -> m ()
(&&=) :: MonadState s m => Iso' s Bool       -> Bool -> m ()
(&&=) :: MonadState s m => Lens' s Bool      -> Bool -> m ()
(&&=) :: MonadState s m => Traversal' s Bool -> Bool -> m ()
value(||=) :: MonadState s m => ASetter' s Bool -> Bool -> m ()
#

Modify the target(s) of a Lens', 'Iso, Setter or Traversal by taking their logical || with a value.

Example1 expression
execState (do _1 ||= True; _2 ||= False; _3 ||= True; _4 ||= False) (True,True,False,False)(True,True,True,False)
(||=) :: MonadState s m => Setter' s Bool    -> Bool -> m ()
(||=) :: MonadState s m => Iso' s Bool       -> Bool -> m ()
(||=) :: MonadState s m => Lens' s Bool      -> Bool -> m ()
(||=) :: MonadState s m => Traversal' s Bool -> Bool -> m ()
value(<~) :: MonadState s m => ASetter s s a b -> m b -> m ()
#

Run a monadic action, and set all of the targets of a Lens, Setter or Traversal to its result.

(<~) :: MonadState s m => Iso s s a b       -> m b -> m ()
(<~) :: MonadState s m => Lens s s a b      -> m b -> m ()
(<~) :: MonadState s m => Traversal s s a b -> m b -> m ()
(<~) :: MonadState s m => Setter s s a b    -> m b -> m ()

As a reasonable mnemonic, this lets you store the result of a monadic action in a Lens rather than in a local variable.

do foo <- bar
   ...

will store the result in a variable, while

do foo <~ bar
   ...

will store the result in a Lens, Setter, or Traversal.

value(<.=) :: MonadState s m => ASetter s s a b -> b -> m b
#

Set with pass-through

This is useful for chaining assignment without round-tripping through your Monad stack.

do x <- _2 <.= ninety_nine_bottles_of_beer_on_the_wall

If you do not need a copy of the intermediate result, then using l .= d will avoid unused binding warnings.

(<.=) :: MonadState s m => Setter s s a b    -> b -> m b
(<.=) :: MonadState s m => Iso s s a b       -> b -> m b
(<.=) :: MonadState s m => Lens s s a b      -> b -> m b
(<.=) :: MonadState s m => Traversal s s a b -> b -> m b
value(<?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m b
#

Set Just a value with pass-through

This is useful for chaining assignment without round-tripping through your Monad stack.

do x <- at "foo" <?= ninety_nine_bottles_of_beer_on_the_wall

If you do not need a copy of the intermediate result, then using l ?= d will avoid unused binding warnings.

(<?=) :: MonadState s m => Setter s s a (Maybe b)    -> b -> m b
(<?=) :: MonadState s m => Iso s s a (Maybe b)       -> b -> m b
(<?=) :: MonadState s m => Lens s s a (Maybe b)      -> b -> m b
(<?=) :: MonadState s m => Traversal s s a (Maybe b) -> b -> m b
value(<>~) :: Semigroup a => ASetter s t a a -> a -> s -> t
#

Modify the target of a Semigroup value by using (<>).

Example1 expression
(Sum a,b) & _1 <>~ Sum c(Sum {getSum = a + c},b)
Example1 expression
(Sum a,Sum b) & both <>~ Sum c(Sum {getSum = a + c},Sum {getSum = b + c})
Example1 expression
both <>~ "!!!" $ ("hello","world")("hello!!!","world!!!")
(<>~) :: Semigroup a => Setter s t a a    -> a -> s -> t
(<>~) :: Semigroup a => Iso s t a a       -> a -> s -> t
(<>~) :: Semigroup a => Lens s t a a      -> a -> s -> t
(<>~) :: Semigroup a => Traversal s t a a -> a -> s -> t
value(<>=) :: (MonadState s m, Semigroup a) => ASetter' s a -> a -> m ()
#

Modify the target(s) of a Lens', Iso, Setter or Traversal by using (<>).

Example1 expression
execState (do _1 <>= Sum c; _2 <>= Product d) (Sum a,Product b)(Sum {getSum = a + c},Product {getProduct = b * d})
Example1 expression
execState (both <>= "!!!") ("hello","world")("hello!!!","world!!!")
(<>=) :: (MonadState s m, Semigroup a) => Setter' s a -> a -> m ()
(<>=) :: (MonadState s m, Semigroup a) => Iso' s a -> a -> m ()
(<>=) :: (MonadState s m, Semigroup a) => Lens' s a -> a -> m ()
(<>=) :: (MonadState s m, Semigroup a) => Traversal' s a -> a -> m ()
value(<>:~) :: Semigroup b => ASetter s t b b -> b -> s -> t
#

Modify the target of a Semigroup value by using (<>). However, unlike <>~, it is prepend to the head side.

Example1 expression
["world"] & id <>:~ ["hello"]["hello","world"]
Example1 expression
(["world"], ["lens"]) & _1 <>:~ ["hello"](["hello","world"],["lens"])
value(.@=) :: MonadState s m => AnIndexedSetter i s s a b -> (i -> b) -> m ()
#

Replace 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 .= b ≡ l .@= const b
(.@=) :: MonadState s m => IndexedSetter i s s a b    -> (i -> b) -> m ()
(.@=) :: MonadState s m => IndexedLens i s s a b      -> (i -> b) -> m ()
(.@=) :: MonadState s m => IndexedTraversal i s t a b -> (i -> b) -> m ()
value(%@=)
  1. :: MonadState s m
  2. => AnIndexedSetter i s s a b
  3. -> i -> a -> b
  4. -> m ()
#

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 ()