module Optics.State.Operators (
(.=), (?=), (%=),
(%%=),
(<.=), (<?=), (<%=),
(<<.=), (<<?=), (<<%=),
PermeableOptic (..),
) where
import Control.Monad.State (MonadState)
import qualified Control.Monad.State as State
import Optics.Core
import Optics.Passthrough
import Optics.State
import Optics.View
infix 4 .=, ?=, %=
(.=)
:: (Is k A_Setter, MonadState s m)
=> Optic k is s s a b
-> b
-> m ()
.= :: Optic k is s s a b -> b -> m ()
(.=) = Optic k is s s a b -> b -> m ()
forall (k :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (a :: OpticKind)
(b :: OpticKind).
(Is k A_Setter, MonadState s m) =>
Optic k is s s a b -> b -> m ()
assign
{-# INLINE (.=) #-}
(?=)
:: (Is k A_Setter, MonadState s m)
=> Optic k is s s (Maybe a) (Maybe b)
-> b
-> m ()
?= :: Optic k is s s (Maybe a) (Maybe b) -> b -> m ()
(?=) = \Optic k is s s (Maybe a) (Maybe b)
o -> Optic k is s s (Maybe a) (Maybe b) -> Maybe b -> m ()
forall (k :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (a :: OpticKind)
(b :: OpticKind).
(Is k A_Setter, MonadState s m) =>
Optic k is s s a b -> b -> m ()
assign Optic k is s s (Maybe a) (Maybe b)
o (Maybe b -> m ()) -> (b -> Maybe b) -> b -> m ()
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. b -> Maybe b
forall (a :: OpticKind). a -> Maybe a
Just
{-# INLINE (?=) #-}
(%=)
:: (Is k A_Setter, MonadState s m)
=> Optic k is s s a b
-> (a -> b)
-> m ()
%= :: Optic k is s s a b -> (a -> b) -> m ()
(%=) = Optic k is s s a b -> (a -> b) -> m ()
forall (k :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (a :: OpticKind)
(b :: OpticKind).
(Is k A_Setter, MonadState s m) =>
Optic k is s s a b -> (a -> b) -> m ()
modifying
{-# INLINE (%=) #-}
infix 4 %%=
(%%=)
:: (PermeableOptic k r, MonadState s m)
=> Optic k is s s a b
-> (a -> (r, b))
-> m (ViewResult k r)
Optic k is s s a b
o %%= :: Optic k is s s a b -> (a -> (r, b)) -> m (ViewResult k r)
%%= a -> (r, b)
f = (s -> (ViewResult k r, s)) -> m (ViewResult k r)
forall (s :: OpticKind) (m :: OpticKind -> OpticKind)
(a :: OpticKind).
MonadState s m =>
(s -> (a, s)) -> m a
State.state (Optic k is s s a b -> (a -> (r, b)) -> s -> (ViewResult k r, s)
forall (k :: OpticKind) (r :: OpticKind) (is :: IxList)
(s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
PermeableOptic k r =>
Optic k is s t a b -> (a -> (r, b)) -> s -> (ViewResult k r, t)
passthrough Optic k is s s a b
o a -> (r, b)
f)
{-# INLINE (%%=) #-}
infix 4 <.=, <?=, <%=
(<%=)
:: (PermeableOptic k b, MonadState s m)
=> Optic k is s s a b
-> (a -> b)
-> m (ViewResult k b)
Optic k is s s a b
o <%= :: Optic k is s s a b -> (a -> b) -> m (ViewResult k b)
<%= a -> b
f = Optic k is s s a b
o Optic k is s s a b -> (a -> (b, b)) -> m (ViewResult k b)
forall (k :: OpticKind) (r :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (a :: OpticKind)
(b :: OpticKind).
(PermeableOptic k r, MonadState s m) =>
Optic k is s s a b -> (a -> (r, b)) -> m (ViewResult k r)
%%= \a
a -> let b :: b
b = a -> b
f a
a in (b
b, b
b)
{-# INLINE (<%=) #-}
(<?=)
:: (PermeableOptic k (Maybe b), MonadState s m)
=> Optic k is s s (Maybe a) (Maybe b)
-> b
-> m (ViewResult k (Maybe b))
Optic k is s s (Maybe a) (Maybe b)
o <?= :: Optic k is s s (Maybe a) (Maybe b)
-> b -> m (ViewResult k (Maybe b))
<?= b
b = Optic k is s s (Maybe a) (Maybe b)
o Optic k is s s (Maybe a) (Maybe b)
-> Maybe b -> m (ViewResult k (Maybe b))
forall (k :: OpticKind) (b :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (a :: OpticKind).
(PermeableOptic k b, MonadState s m) =>
Optic k is s s a b -> b -> m (ViewResult k b)
<.= b -> Maybe b
forall (a :: OpticKind). a -> Maybe a
Just b
b
{-# INLINE (<?=) #-}
(<.=)
:: (PermeableOptic k b, MonadState s m)
=> Optic k is s s a b
-> b
-> m (ViewResult k b)
Optic k is s s a b
o <.= :: Optic k is s s a b -> b -> m (ViewResult k b)
<.= b
b = Optic k is s s a b
o Optic k is s s a b -> (a -> b) -> m (ViewResult k b)
forall (k :: OpticKind) (b :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (a :: OpticKind).
(PermeableOptic k b, MonadState s m) =>
Optic k is s s a b -> (a -> b) -> m (ViewResult k b)
<%= b -> a -> b
forall (a :: OpticKind) (b :: OpticKind). a -> b -> a
const b
b
{-# INLINE (<.=) #-}
infix 4 <<.=, <<?=, <<%=
(<<%=)
:: (PermeableOptic k a, MonadState s m)
=> Optic k is s s a b
-> (a -> b)
-> m (ViewResult k a)
Optic k is s s a b
o <<%= :: Optic k is s s a b -> (a -> b) -> m (ViewResult k a)
<<%= a -> b
f = Optic k is s s a b
o Optic k is s s a b -> (a -> (a, b)) -> m (ViewResult k a)
forall (k :: OpticKind) (r :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (a :: OpticKind)
(b :: OpticKind).
(PermeableOptic k r, MonadState s m) =>
Optic k is s s a b -> (a -> (r, b)) -> m (ViewResult k r)
%%= \a
a -> (a
a, a -> b
f a
a)
{-# INLINE (<<%=) #-}
(<<?=)
:: (PermeableOptic k (Maybe a), MonadState s m)
=> Optic k is s s (Maybe a) (Maybe b)
-> b
-> m (ViewResult k (Maybe a))
Optic k is s s (Maybe a) (Maybe b)
o <<?= :: Optic k is s s (Maybe a) (Maybe b)
-> b -> m (ViewResult k (Maybe a))
<<?= b
b = Optic k is s s (Maybe a) (Maybe b)
o Optic k is s s (Maybe a) (Maybe b)
-> Maybe b -> m (ViewResult k (Maybe a))
forall (k :: OpticKind) (a :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (b :: OpticKind).
(PermeableOptic k a, MonadState s m) =>
Optic k is s s a b -> b -> m (ViewResult k a)
<<.= b -> Maybe b
forall (a :: OpticKind). a -> Maybe a
Just b
b
{-# INLINE (<<?=) #-}
(<<.=)
:: (PermeableOptic k a, MonadState s m)
=> Optic k is s s a b
-> b
-> m (ViewResult k a)
Optic k is s s a b
o <<.= :: Optic k is s s a b -> b -> m (ViewResult k a)
<<.= b
b = Optic k is s s a b
o Optic k is s s a b -> (a -> b) -> m (ViewResult k a)
forall (k :: OpticKind) (a :: OpticKind) (s :: OpticKind)
(m :: OpticKind -> OpticKind) (is :: IxList) (b :: OpticKind).
(PermeableOptic k a, MonadState s m) =>
Optic k is s s a b -> (a -> b) -> m (ViewResult k a)
<<%= b -> a -> b
forall (a :: OpticKind) (b :: OpticKind). a -> b -> a
const b
b
{-# INLINE (<<.=) #-}