Portability | Rank2Types |
---|---|
Stability | provisional |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Safe Haskell | Safe-Inferred |
A
is a generalization of Setter
s t a bfmap
from Functor
. It allows you to map into a
structure and change out the contents, but it isn't strong enough to allow you to
enumerate those contents. Starting with fmap ::
we monomorphize the type to obtain Functor
f => (a -> b) -> f a -> f b(a -> b) -> s -> t
and then decorate it with Identity
to obtain
typeSetter
s t a b = (a ->Identity
b) -> s ->Identity
t
Every Traversal
is a valid Setter
, since Identity
is Applicative
.
Everything you can do with a Functor
, you can do with a Setter
. There
are combinators that generalize fmap
and (<$
).
- type Setter s t a b = forall f. Settable f => (a -> f b) -> s -> f t
- sets :: ((a -> b) -> s -> t) -> Setter s t a b
- mapped :: Functor f => Setter (f a) (f b) a b
- lifted :: Monad m => Setter (m a) (m b) a b
- over :: Setting s t a b -> (a -> b) -> s -> t
- mapOf :: Setting s t a b -> (a -> b) -> s -> t
- set :: Setting s t a b -> b -> s -> t
- (.~) :: Setting s t a b -> b -> s -> t
- (%~) :: Setting s t a b -> (a -> b) -> s -> t
- (+~) :: Num a => Setting s t a a -> a -> s -> t
- (-~) :: Num a => Setting s t a a -> a -> s -> t
- (*~) :: Num a => Setting s t a a -> a -> s -> t
- (//~) :: Fractional s => Setting a b s s -> s -> a -> b
- (^~) :: (Num a, Integral e) => Setting s t a a -> e -> s -> t
- (^^~) :: (Fractional a, Integral e) => Setting s t a a -> e -> s -> t
- (**~) :: Floating a => Setting s t a a -> a -> s -> t
- (||~) :: Setting s t Bool Bool -> Bool -> s -> t
- (&&~) :: Setting s t Bool Bool -> Bool -> s -> t
- (<.~) :: Setting s t a b -> b -> s -> (b, t)
- (?~) :: Setting s t a (Maybe b) -> b -> s -> t
- (<?~) :: Setting s t a (Maybe b) -> b -> s -> (b, t)
- assign :: MonadState s m => Setting s s a b -> b -> m ()
- (.=) :: MonadState s m => Setting s s a b -> b -> m ()
- (%=) :: MonadState s m => Setting s s a b -> (a -> b) -> m ()
- (+=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()
- (-=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()
- (*=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()
- (//=) :: (MonadState s m, Fractional a) => SimpleSetting s a -> a -> m ()
- (^=) :: (MonadState s m, Num a, Integral e) => SimpleSetting s a -> e -> m ()
- (^^=) :: (MonadState s m, Fractional a, Integral e) => SimpleSetting s a -> e -> m ()
- (**=) :: (MonadState s m, Floating a) => SimpleSetting s a -> a -> m ()
- (||=) :: MonadState s m => SimpleSetting s Bool -> Bool -> m ()
- (&&=) :: MonadState s m => SimpleSetting s Bool -> Bool -> m ()
- (<.=) :: MonadState s m => Setting s s a b -> b -> m b
- (?=) :: MonadState s m => Setting s s a (Maybe b) -> b -> m ()
- (<?=) :: MonadState s m => Setting s s a (Maybe b) -> b -> m b
- (<~) :: MonadState s m => Setting s s a b -> m b -> m ()
- newtype ReifiedSetter s t a b = ReifySetter {
- reflectSetter :: Setter s t a b
- type Setting s t a b = (a -> Mutator b) -> s -> Mutator t
- type SimpleSetting s a = Setting s s a a
- type SimpleSetter s a = Setter s s a a
- type SimpleReifiedSetter s a = ReifiedSetter s s a a
- class Applicative f => Settable f
- data Mutator a
Setters
type Setter s t a b = forall f. Settable f => (a -> f b) -> s -> f tSource
The only Lens
-like law that can apply to a Setter
l
is that
set
l y (set
l x a) ≡set
l y a
You can't view
a Setter
in general, so the other two laws are irrelevant.
However, two Functor
laws apply to a Setter
:
over
lid
≡id
over
l f.
over
l g ≡over
l (f.
g)
These an be stated more directly:
lpure
≡pure
l f .untainted
. l g ≡ l (f .untainted
. g)
You can compose a Setter
with a Lens
or a Traversal
using (.
) from the Prelude
and the result is always only a Setter
and nothing more.
Building Setters
Common Setters
mapped :: Functor f => Setter (f a) (f b) a bSource
This setter can be used to map over all of the values in a Functor
.
fmap
≡over
mapped
fmapDefault
≡over
traverse
(<$
) ≡set
mapped
>>>
over mapped (+1) [1,2,3]
[2,3,4]
>>>
set mapped () [1,2,3]
[(),(),()]
>>>
mapped.mapped %~ (+1) $ [[1,2],[3]]
[[2,3],[4]]
>>>
over (mapped._2) length [("hello","world"),("leaders","!!!")]
[("hello",5),("leaders",3)]
Functional Combinators
over :: Setting s t a b -> (a -> b) -> s -> tSource
Modify the target of a Lens
or all the targets of a Setter
or Traversal
with a function.
fmap
≡over
mapped
fmapDefault
≡over
traverse
sets
.
over
≡id
over
.
sets
≡id
>>>
over mapped (*10) [1,2,3]
[10,20,30]
>>>
over _1 show (10,20)
("10",20)
Another way to view over
is to say that it transformers a Setter
into a
"semantic editor combinator".
over
::Setter
s t a b -> (a -> b) -> s -> t
mapOf :: Setting s t a b -> (a -> b) -> s -> tSource
Modify the target of a Lens
or all the targets of a Setter
or Traversal
with a function. This is an alias for over
that is provided for consistency.
mapOf
≡over
fmap
≡mapOf
mapped
fmapDefault
≡mapOf
traverse
sets
.
mapOf
≡id
mapOf
.
sets
≡id
>>>
mapOf mapped (+1) [1,2,3,4]
[2,3,4,5]
>>>
mapOf _1 (+1) (1,2)
(2,2)
>>>
mapOf both (+1) (1,2)
(2,3)
mapOf
::Setter
s t a b -> (a -> b) -> s -> tmapOf
::Iso
s t a b -> (a -> b) -> s -> tmapOf
::Lens
s t a b -> (a -> b) -> s -> tmapOf
::Traversal
s t a b -> (a -> b) -> s -> t
set :: Setting s t a b -> b -> s -> tSource
Replace the target of a Lens
or all of the targets of a Setter
or Traversal
with a constant value.
(<$
) ≡set
mapped
>>>
set _2 "hello" (1,())
(1,"hello")
>>>
set mapped () [1,2,3,4]
[(),(),(),()]
Note: Attempting to set
a Fold
or Getter
will fail at compile time with an
relatively nice error message.
set
::Setter
s t a b -> b -> s -> tset
::Iso
s t a b -> b -> s -> tset
::Lens
s t a b -> b -> s -> tset
::Traversal
s t a b -> b -> s -> t
(.~) :: Setting s t a b -> b -> s -> tSource
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
>>>
_1 .~ "hello" $ (42,"world")
("hello","world")
(.~
) ::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
(%~) :: Setting s t a b -> (a -> b) -> s -> tSource
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
%~
ffmapDefault
f ≡traverse
%~
f
>>>
_2 %~ length $ (1,"hello")
(1,5)
>>>
traverse %~ (+1) $ [1,2,3]
[2,3,4]
>>>
_2 %~ (+1) $ (3,4)
(3,5)
>>>
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
(+~) :: Num a => Setting s t a a -> a -> s -> tSource
Increment the target(s) of a numerically valued Lens
, Setter
or Traversal
>>>
_1 +~ 1 $ (1,2)
(2,2)
>>>
both +~ 2 $ (5,6)
(7,8)
(+~
) :: Num a =>Simple
Setter
s a -> a -> s -> s (+~
) :: Num a =>Simple
Iso
s a -> a -> s -> s (+~
) :: Num a =>Simple
Lens
s a -> a -> s -> s (+~
) :: Num a =>Simple
Traversal
s a -> a -> s -> s
(-~) :: Num a => Setting s t a a -> a -> s -> tSource
Decrement the target(s) of a numerically valued Lens
, Iso
, Setter
or Traversal
>>>
_1 -~ 2 $ (1,2)
(-1,2)
>>>
mapped.mapped -~ 1 $ [[4,5],[6,7]]
[[3,4],[5,6]]
(-~
) ::Num
a =>Simple
Setter
s a -> a -> s -> s (-~
) ::Num
a =>Simple
Iso
s a -> a -> s -> s (-~
) ::Num
a =>Simple
Lens
s a -> a -> s -> s (-~
) ::Num
a =>Simple
Traversal
s a -> a -> s -> s
(*~) :: Num a => Setting s t a a -> a -> s -> tSource
Multiply the target(s) of a numerically valued Lens
, Iso
, Setter
or Traversal
>>>
_2 *~ 4 $ (1,2)
(1,8)
>>>
mapped *~ 2 $ Just 24
Just 48
(*~
) ::Num
a =>Simple
Setter
s a -> a -> s -> s (*~
) ::Num
a =>Simple
Iso
s a -> a -> s -> s (*~
) ::Num
a =>Simple
Lens
s a -> a -> s -> s (*~
) ::Num
a =>Simple
Traversal
s a -> a -> s -> s
(//~) :: Fractional s => Setting a b s s -> s -> a -> bSource
Divide the target(s) of a numerically valued Lens
, Iso
, Setter
or Traversal
>>>
_2 //~ 2 $ ("Hawaii",10)
("Hawaii",5.0)
(//~
) ::Fractional
a =>Simple
Setter
s a -> a -> s -> s (//~
) ::Fractional
a =>Simple
Iso
s a -> a -> s -> s (//~
) ::Fractional
a =>Simple
Lens
s a -> a -> s -> s (//~
) ::Fractional
a =>Simple
Traversal
s a -> a -> s -> s
(^~) :: (Num a, Integral e) => Setting s t a a -> e -> s -> tSource
Raise the target(s) of a numerically valued Lens
, Setter
or Traversal
to a non-negative integral power
>>>
_2 ^~ 2 $ (1,3)
(1,9)
(^~
) :: (Num
a,Integral
e) =>Simple
Setter
s a -> e -> s -> s (^~
) :: (Num
a,Integral
e) =>Simple
Iso
s a -> e -> s -> s (^~
) :: (Num
a,Integral
e) =>Simple
Lens
s a -> e -> s -> s (^~
) :: (Num
a,Integral
e) =>Simple
Traversal
s a -> e -> s -> s
(^^~) :: (Fractional a, Integral e) => Setting s t a a -> e -> s -> tSource
Raise the target(s) of a fractionally valued Lens
, Setter
or Traversal
to an integral power
>>>
_2 ^^~ (-1) $ (1,2)
(1,0.5)
(^^~
) :: (Fractional
a,Integral
e) =>Simple
Setter
s a -> e -> s -> s (^^~
) :: (Fractional
a,Integral
e) =>Simple
Iso
s a -> e -> s -> s (^^~
) :: (Fractional
a,Integral
e) =>Simple
Lens
s a -> e -> s -> s (^^~
) :: (Fractional
a,Integral
e) =>Simple
Traversal
s a -> e -> s -> s
(**~) :: Floating a => Setting s t a a -> a -> s -> tSource
Raise the target(s) of a floating-point valued Lens
, Setter
or Traversal
to an arbitrary power.
>>>
_2 **~ pi $ (1,3)
(1,31.54428070019754)
(**~
) ::Floating
a =>Simple
Setter
s a -> a -> s -> s (**~
) ::Floating
a =>Simple
Iso
s a -> a -> s -> s (**~
) ::Floating
a =>Simple
Lens
s a -> a -> s -> s (**~
) ::Floating
a =>Simple
Traversal
s a -> a -> s -> s
(||~) :: Setting s t Bool Bool -> Bool -> s -> tSource
Logically ||
the target(s) of a Bool
-valued Lens
or Setter
>>>
both ||~ True $ (False,True)
(True,True)
>>>
both ||~ False $ (False,True)
(False,True)
(||~
) ::Simple
Setter
sBool
->Bool
-> s -> s (||~
) ::Simple
Iso
sBool
->Bool
-> s -> s (||~
) ::Simple
Lens
sBool
->Bool
-> s -> s (||~
) ::Simple
Traversal
sBool
->Bool
-> s -> s
(&&~) :: Setting s t Bool Bool -> Bool -> s -> tSource
Logically &&
the target(s) of a Bool
-valued Lens
or Setter
>>>
both &&~ True $ (False, True)
(False,True)
>>>
both &&~ False $ (False, True)
(False,False)
(&&~
) ::Simple
Setter
sBool
->Bool
-> s -> s (&&~
) ::Simple
Iso
sBool
->Bool
-> s -> s (&&~
) ::Simple
Lens
sBool
->Bool
-> s -> s (&&~
) ::Simple
Traversal
sBool
->Bool
-> s -> s
(<.~) :: Setting s t a b -> b -> s -> (b, t)Source
Set 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
directly is a good idea.
.~
t
>>>
_3 <.~ "world" $ ("good","morning","vietnam")
("world",("good","morning","world"))
>>>
import Data.Map as Map
>>>
_2.at "hello" <.~ Just "world" $ (42,Map.fromList [("goodnight","gracie")])
(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)
(<?~) :: Setting s t a (Maybe b) -> b -> s -> (b, t)Source
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
directly is a good idea.
?~
d
>>>
import Data.Map as Map
>>>
_2.at "hello" <?~ "world" $ (42,Map.fromList [("goodnight","gracie")])
("world",(42,fromList [("goodnight","gracie"),("hello","world")]))
(<?~
) ::Setter
s t a b -> (Maybe
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)
State Combinators
assign :: MonadState s m => Setting s s a b -> b -> m ()Source
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 alias for (.=
).
assign
::MonadState
s m =>Simple
Iso
s a -> a -> m ()assign
::MonadState
s m =>Simple
Lens
s a -> a -> m ()assign
::MonadState
s m =>Simple
Traversal
s a -> a -> m ()assign
::MonadState
s m =>Simple
Setter
s a -> a -> m ()
(.=) :: MonadState s m => Setting s s a b -> b -> m ()Source
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
.
(.=
) ::MonadState
s m =>Simple
Iso
s a -> a -> m () (.=
) ::MonadState
s m =>Simple
Lens
s a -> a -> m () (.=
) ::MonadState
s m =>Simple
Traversal
s a -> a -> m () (.=
) ::MonadState
s m =>Simple
Setter
s a -> a -> m ()
(%=) :: MonadState s m => Setting s s a b -> (a -> b) -> m ()Source
Map over the target of a Lens
or all of the targets of a Setter
or Traversal
in our monadic state.
(%=
) ::MonadState
s m =>Simple
Iso
s a -> (a -> a) -> m () (%=
) ::MonadState
s m =>Simple
Lens
s a -> (a -> a) -> m () (%=
) ::MonadState
s m =>Simple
Traversal
s a -> (a -> a) -> m () (%=
) ::MonadState
s m =>Simple
Setter
s a -> (a -> a) -> m ()
(+=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()Source
Modify the target(s) of a Simple
Lens
, Iso
, Setter
or Traversal
by adding a value
Example:
fresh :: MonadState Int m => m Int fresh = doid
+=
1use
id
(+=
) :: (MonadState
s m,Num
a) =>Simple
Setter
s a -> a -> m () (+=
) :: (MonadState
s m,Num
a) =>Simple
Iso
s a -> a -> m () (+=
) :: (MonadState
s m,Num
a) =>Simple
Lens
s a -> a -> m () (+=
) :: (MonadState
s m,Num
a) =>Simple
Traversal
s a -> a -> m ()
(-=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()Source
Modify the target(s) of a Simple
Lens
, Iso
, Setter
or Traversal
by subtracting a value
(-=
) :: (MonadState
s m,Num
a) =>Simple
Setter
s a -> a -> m () (-=
) :: (MonadState
s m,Num
a) =>Simple
Iso
s a -> a -> m () (-=
) :: (MonadState
s m,Num
a) =>Simple
Lens
s a -> a -> m () (-=
) :: (MonadState
s m,Num
a) =>Simple
Traversal
s a -> a -> m ()
(*=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()Source
Modify the target(s) of a Simple
Lens
, Iso
, Setter
or Traversal
by multiplying by value.
(*=
) :: (MonadState
s m,Num
a) =>Simple
Setter
s a -> a -> m () (*=
) :: (MonadState
s m,Num
a) =>Simple
Iso
s a -> a -> m () (*=
) :: (MonadState
s m,Num
a) =>Simple
Lens
s a -> a -> m () (*=
) :: (MonadState
s m,Num
a) =>Simple
Traversal
s a -> a -> m ()
(//=) :: (MonadState s m, Fractional a) => SimpleSetting s a -> a -> m ()Source
Modify the target(s) of a Simple
Lens
, Iso
, Setter
or Traversal
by dividing by a value.
(//=
) :: (MonadState
s m,Fractional
a) =>Simple
Setter
s a -> a -> m () (//=
) :: (MonadState
s m,Fractional
a) =>Simple
Iso
s a -> a -> m () (//=
) :: (MonadState
s m,Fractional
a) =>Simple
Lens
s a -> a -> m () (//=
) :: (MonadState
s m,Fractional
a) =>Simple
Traversal
s a -> a -> m ()
(^=) :: (MonadState s m, Num a, Integral e) => SimpleSetting s a -> e -> m ()Source
Raise the target(s) of a numerically valued Lens
, Setter
or Traversal
to a non-negative integral power.
(^=
) :: (MonadState
s m,Num
a,Integral
e) =>Simple
Setter
s a -> e -> m () (^=
) :: (MonadState
s m,Num
a,Integral
e) =>Simple
Iso
s a -> e -> m () (^=
) :: (MonadState
s m,Num
a,Integral
e) =>Simple
Lens
s a -> e -> m () (^=
) :: (MonadState
s m,Num
a,Integral
e) =>Simple
Traversal
s a -> e -> m ()
(^^=) :: (MonadState s m, Fractional a, Integral e) => SimpleSetting s a -> e -> m ()Source
Raise the target(s) of a numerically valued Lens
, Setter
or Traversal
to an integral power.
(^^=
) :: (MonadState
s m,Fractional
a,Integral
e) =>Simple
Setter
s a -> e -> m () (^^=
) :: (MonadState
s m,Fractional
a,Integral
e) =>Simple
Iso
s a -> e -> m () (^^=
) :: (MonadState
s m,Fractional
a,Integral
e) =>Simple
Lens
s a -> e -> m () (^^=
) :: (MonadState
s m,Fractional
a,Integral
e) =>Simple
Traversal
s a -> e -> m ()
(**=) :: (MonadState s m, Floating a) => SimpleSetting s a -> a -> m ()Source
Raise the target(s) of a numerically valued Lens
, Setter
or Traversal
to an arbitrary power
(**=
) :: (MonadState
s m,Floating
a) =>Simple
Setter
s a -> a -> m () (**=
) :: (MonadState
s m,Floating
a) =>Simple
Iso
s a -> a -> m () (**=
) :: (MonadState
s m,Floating
a) =>Simple
Lens
s a -> a -> m () (**=
) :: (MonadState
s m,Floating
a) =>Simple
Traversal
s a -> a -> m ()
(||=) :: MonadState s m => SimpleSetting s Bool -> Bool -> m ()Source
Modify the target(s) of a Simple
Lens
, 'Iso, Setter
or Traversal
by taking their logical ||
with a value
(||=
) ::MonadState
s m =>Simple
Setter
sBool
->Bool
-> m () (||=
) ::MonadState
s m =>Simple
Iso
sBool
->Bool
-> m () (||=
) ::MonadState
s m =>Simple
Lens
sBool
->Bool
-> m () (||=
) ::MonadState
s m =>Simple
Traversal
sBool
->Bool
-> m ()
(&&=) :: MonadState s m => SimpleSetting s Bool -> Bool -> m ()Source
Modify the target(s) of a Simple
Lens
, Iso
, Setter
or Traversal
by taking their logical &&
with a value
(&&=
) ::MonadState
s m =>Simple
Setter
sBool
->Bool
-> m () (&&=
) ::MonadState
s m =>Simple
Iso
sBool
->Bool
-> m () (&&=
) ::MonadState
s m =>Simple
Lens
sBool
->Bool
-> m () (&&=
) ::MonadState
s m =>Simple
Traversal
sBool
->Bool
-> m ()
(<.=) :: MonadState s m => Setting s s a b -> b -> m bSource
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
(?=) :: MonadState s m => Setting s s a (Maybe b) -> b -> m ()Source
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.
(?=
) ::MonadState
s m =>Simple
Iso
s (Maybe
a) -> a -> m () (?=
) ::MonadState
s m =>Simple
Lens
s (Maybe
a) -> a -> m () (?=
) ::MonadState
s m =>Simple
Traversal
s (Maybe
a) -> a -> m () (?=
) ::MonadState
s m =>Simple
Setter
s (Maybe
a) -> a -> m ()
(<?=) :: MonadState s m => Setting s s a (Maybe b) -> b -> m bSource
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
(<~) :: MonadState s m => Setting s s a b -> m b -> m ()Source
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
...
Storing Setters
newtype ReifiedSetter s t a b Source
Reify a setter so it can be stored safely in a container.
ReifySetter | |
|
Setter Internals
type SimpleSetting s a = Setting s s a aSource
This is a useful alias for use when consuming a SimpleSetter
.
Most user code will never have to use this type.
typeSimpleSetting
m =Simple
Setting
Simplicity
type SimpleSetter s a = Setter s s a aSource
A Simple Setter is just a Setter
that doesn't change the types.
These are particularly common when talking about monomorphic containers. e.g.
sets
Data.Text.map ::SimpleSetter
Text
Char
typeSimpleSetter
=Simple
Setter
type SimpleReifiedSetter s a = ReifiedSetter s s a aSource
Exported for legible error messages
class Applicative f => Settable f Source