Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Setter s t a b = forall p. (Choice p, Strong p, Representable p, Applicative (Rep p), Distributive (Rep p)) => Optic p s t a b
- type Setter' s a = Setter s s a a
- setter :: ((a -> b) -> s -> t) -> Setter s t a b
- isetter :: ((i -> a -> b) -> s -> t) -> Ixsetter i s t a b
- closing :: (((s -> a) -> b) -> t) -> Setter s t a b
- type Resetter s t a b = forall p. (Choice p, Closed p, Corepresentable p, Coapplicative (Corep p), Traversable (Corep p)) => Optic p s t a b
- type Resetter' s a = Resetter s s a a
- resetter :: ((a -> t) -> s -> t) -> Resetter s t a t
- ksetter :: ((k -> a -> t) -> s -> t) -> Cxsetter k s t a t
- cod :: Profunctor p => Setter (p r a) (p r b) a b
- dom :: Profunctor p => Setter (p b r) (p a r) a b
- bound :: Monad m => Setter (m a) (m b) a (m b)
- fmapped :: Functor f => Setter (f a) (f b) a b
- contramapped :: Contravariant f => Setter (f b) (f a) a b
- exmapped :: Exception e1 => Exception e2 => Setter s s e1 e2
- adjusted :: Adjustable f => Key f -> Setter' (f a) a
- liftedA :: Applicative f => Setter (f a) (f b) a b
- liftedM :: Monad m => Setter (m a) (m b) a b
- forwarded :: Setter (ReaderT r2 m a) (ReaderT r1 m a) r1 r2
- censored :: MonadWriter w m => Setter' (m a) w
- zipped :: Setter (u -> v -> a) (u -> v -> b) a b
- modded :: (a -> Bool) -> Setter' (a -> b) b
- cond :: (a -> Bool) -> Setter' a a
- imapped :: Keyed f => Ixsetter (Key f) (f a) (f b) a b
- imappedRep :: Representable f => Ixsetter (Rep f) (f a) (f b) a b
- withIxsetter :: IndexedOptic (->) i s t a b -> (i -> a -> b) -> i -> s -> t
- withCxsetter :: CoindexedOptic (->) k s t a b -> (k -> a -> b) -> k -> s -> t
- set :: Optic (->) s t a b -> b -> s -> t
- iset :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> b) -> s -> t
- kset :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> b) -> s -> t
- (.~) :: Optic (->) s t a b -> b -> s -> t
- (%~) :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> b) -> s -> t
- (#~) :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> b) -> s -> t
- over :: Optic (->) s t a b -> (a -> b) -> s -> t
- iover :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t
- kover :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> a -> b) -> s -> t
- (..~) :: Optic (->) s t a b -> (a -> b) -> s -> t
- (%%~) :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t
- (##~) :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> a -> b) -> s -> t
- (<>~) :: Semigroup a => Optic (->) s t a a -> a -> s -> t
- locally :: MonadReader s m => Optic (->) s s a b -> (a -> b) -> m r -> m r
- scribe :: MonadWriter w m => Monoid b => Optic (->) s w a b -> s -> m ()
- assigns :: MonadState s m => Optic (->) s s a b -> b -> m ()
- modifies :: MonadState s m => Optic (->) s s a b -> (a -> b) -> m ()
- (.=) :: MonadState s m => Optic (->) s s a b -> b -> m ()
- (%=) :: MonadState s m => (Additive - Monoid) i => AIxsetter i s s a b -> (i -> b) -> m ()
- (#=) :: MonadState s m => (Additive - Monoid) k => ACxsetter k s s a b -> (k -> b) -> m ()
- (..=) :: MonadState s m => Optic (->) s s a b -> (a -> b) -> m ()
- (%%=) :: MonadState s m => (Additive - Monoid) i => AIxsetter i s s a b -> (i -> a -> b) -> m ()
- (##=) :: MonadState s m => (Additive - Monoid) k => ACxsetter k s s a b -> (k -> a -> b) -> m ()
- (<>=) :: MonadState s m => Semigroup a => Optic' (->) s a -> a -> m ()
Setter
type Setter s t a b = forall p. (Choice p, Strong p, Representable p, Applicative (Rep p), Distributive (Rep p)) => Optic p s t a b Source #
A Setter
modifies part of a structure.
\( \mathsf{Setter}\;S\;A = \exists F : \mathsf{Functor}, S \equiv F\,A \)
setter :: ((a -> b) -> s -> t) -> Setter s t a b Source #
To demote an optic to a semantic edit combinator, use the section (l ..~)
or over l
.
>>>
[("The",0),("quick",1),("brown",1),("fox",2)] & setter fmap . first' ..~ Prelude.length
[(3,0),(5,1),(5,1),(3,2)]
Caution: In order for the generated optic to be well-defined, you must ensure that the input function satisfies the following properties:
abst id ≡ id
abst f . abst g ≡ abst (f . g)
More generally, a profunctor optic must be monoidal as a natural transformation:
o id ≡ id
o (
Procompose
p q) ≡Procompose
(o p) (o q)
See Property
.
isetter :: ((i -> a -> b) -> s -> t) -> Ixsetter i s t a b Source #
Build an Ixsetter
from an indexed function.
isetter
.
iover
≡id
iover
.
isetter
≡id
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
iabst (const id) ≡ id
fmap (iabst $ const f) . (iabst $ const g) ≡ iabst (const $ f . g)
See Property
.
Resetter
type Resetter s t a b = forall p. (Choice p, Closed p, Corepresentable p, Coapplicative (Corep p), Traversable (Corep p)) => Optic p s t a b Source #
ksetter :: ((k -> a -> t) -> s -> t) -> Cxsetter k s t a t Source #
TODO: Document
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
kabst (const id) ≡ id
fmap (kabst $ const f) . (kabst $ const g) ≡ kabst (const $ f . g)
See Property
.
Optics
cod :: Profunctor p => Setter (p r a) (p r b) a b Source #
Map covariantly over the output of a Profunctor
.
The most common profunctor to use this with is (->)
.
(dom ..~ f) g x ≡ f (g x) cod @(->) ≡withGrate
closed
closing
>>>
(cod ..~ show) length [1,2,3]
"3"
dom :: Profunctor p => Setter (p b r) (p a r) a b Source #
Map contravariantly over the input of a Profunctor
.
The most common profunctor to use this with is (->)
.
(dom ..~ f) g x ≡ g (f x)
>>>
(dom ..~ show) length [1,2,3]
7
bound :: Monad m => Setter (m a) (m b) a (m b) Source #
Setter
for monadically transforming a monadic value.
contramapped :: Contravariant f => Setter (f b) (f a) a b Source #
Setter
on each value of a contravariant functor.
contramap
≡over
contramapped
>>>
getPredicate (over contramapped (*2) (Predicate even)) 5
True
>>>
getOp (over contramapped (*5) (Op show)) 100
"500"
exmapped :: Exception e1 => Exception e2 => Setter s s e1 e2 Source #
Map one exception into another as proposed in the paper "A semantics for imprecise exceptions".
>>>
handles (only Overflow) (\_ -> return "caught") $ assert False (return "uncaught") & (exmapped ..~ \ (AssertionFailed _) -> Overflow)
"caught"
exmapped :: Exception e => Setter s s SomeException e
adjusted :: Adjustable f => Key f -> Setter' (f a) a Source #
Setter
on a particular value of an Adjustable
container.
liftedA :: Applicative f => Setter (f a) (f b) a b Source #
censored :: MonadWriter w m => Setter' (m a) w Source #
TODO: Document
zipped :: Setter (u -> v -> a) (u -> v -> b) a b Source #
Setter
on the codomain of a zipping function.
>>>
((,) & zipped ..~ swap) 1 2
(2,1)
cond :: (a -> Bool) -> Setter' a a Source #
Apply a function only when the given condition holds.
See also predicated
& filtered
.
Indexed optics
imappedRep :: Representable f => Ixsetter (Rep f) (f a) (f b) a b Source #
Ixsetter
on each value of a representable functor.
>>>
1 :+ 2 & imappedRep %~ bool 20 10
20 :+ 10
Primitive operators
withIxsetter :: IndexedOptic (->) i s t a b -> (i -> a -> b) -> i -> s -> t Source #
TODO: Document
withCxsetter :: CoindexedOptic (->) k s t a b -> (k -> a -> b) -> k -> s -> t Source #
TODO: Document
Operators
(.~) :: Optic (->) s t a b -> b -> s -> t infixr 4 Source #
Set all referenced fields to the given value.
(#~) :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> b) -> s -> t infixr 4 Source #
Set the focus of a coindexed optic.
See also %~
.
iover :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t Source #
Prefix alias of %%~
.
>>>
iover (iat 1) (+) [1,2,3 :: Int]
[1,3,3]>>>
iover (iat 5) (+) [1,2,3 :: Int]
[1,2,3]
kover :: (Additive - Monoid) k => ACxsetter k s t a b -> (k -> a -> b) -> s -> t Source #
Prefix alias of ##~
.
(..~) :: Optic (->) s t a b -> (a -> b) -> s -> t infixr 4 Source #
Map over an optic.
>>>
Just 1 & just ..~ (+1)
Just 2
>>>
Nothing & just ..~ (+1)
Nothing
>>>
[1,2,3] & fmapped ..~ (*10)
[10,20,30]
>>>
(1,2) & first' ..~ (+1)
(2,2)
>>>
(10,20) & first' ..~ show
("10",20)
(%%~) :: (Additive - Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t infixr 4 Source #
Map over an indexed optic.
See also ##~
.
(<>~) :: Semigroup a => Optic (->) s t a a -> a -> s -> t infixr 4 Source #
Modify the target by adding another value.
>>>
both <>~ "!" $ ("bar","baz")
("bar!","baz!")
mtl
locally :: MonadReader s m => Optic (->) s s a b -> (a -> b) -> m r -> m r Source #
scribe :: MonadWriter w m => Monoid b => Optic (->) s w a b -> s -> m () Source #
Write to a fragment of a larger Writer
format.
assigns :: MonadState s m => Optic (->) s s a b -> b -> m () Source #
Replace the target(s) of a settable in a monadic state.
modifies :: MonadState s m => Optic (->) s s a b -> (a -> b) -> m () Source #
Map over the target(s) of a Setter
in a monadic state.
(.=) :: MonadState s m => Optic (->) s s a b -> b -> m () infix 4 Source #
Replace the target(s) of a settable in a monadic state.
This is an infixversion of assigns
.
>>>
execState (do first' .= 1; second' .= 2) (3,4)
(1,2)>>>
execState (both .= 3) (1,2)
(3,3)
(%=) :: MonadState s m => (Additive - Monoid) i => AIxsetter i s s a b -> (i -> b) -> m () infix 4 Source #
TODO: Document
(#=) :: MonadState s m => (Additive - Monoid) k => ACxsetter k s s a b -> (k -> b) -> m () infix 4 Source #
TODO: Document
(..=) :: MonadState s m => Optic (->) s s a b -> (a -> b) -> m () infix 4 Source #
(%%=) :: MonadState s m => (Additive - Monoid) i => AIxsetter i s s a b -> (i -> a -> b) -> m () infix 4 Source #
TODO: Document