module Optics.State
( modifying
, modifying'
, assign
, assign'
, use
, preuse
) where
import Control.Monad.State
import Optics.Core
modifying
:: (Is k A_Setter, MonadState s m)
=> Optic k is s s a b
-> (a -> b)
-> m ()
modifying :: Optic k is s s a b -> (a -> b) -> m ()
modifying Optic k is s s a b
o = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((s -> s) -> m ()) -> ((a -> b) -> s -> s) -> (a -> b) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic k is s s a b -> (a -> b) -> s -> s
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over Optic k is s s a b
o
{-# INLINE modifying #-}
modifying'
:: (Is k A_Setter, MonadState s m)
=> Optic k is s s a b
-> (a -> b)
-> m ()
modifying' :: Optic k is s s a b -> (a -> b) -> m ()
modifying' Optic k is s s a b
o = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify' ((s -> s) -> m ()) -> ((a -> b) -> s -> s) -> (a -> b) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic k is s s a b -> (a -> b) -> s -> s
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over' Optic k is s s a b
o
{-# INLINE modifying' #-}
assign
:: (Is k A_Setter, MonadState s m)
=> Optic k is s s a b
-> b
-> m ()
assign :: Optic k is s s a b -> b -> m ()
assign Optic k is s s a b
o = Optic k is s s a b -> (a -> b) -> m ()
forall k s (m :: * -> *) (is :: IxList) a b.
(Is k A_Setter, MonadState s m) =>
Optic k is s s a b -> (a -> b) -> m ()
modifying Optic k is s s a b
o ((a -> b) -> m ()) -> (b -> a -> b) -> b -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a -> b
forall a b. a -> b -> a
const
{-# INLINE assign #-}
assign'
:: (Is k A_Setter, MonadState s m)
=> Optic k is s s a b
-> b
-> m ()
assign' :: Optic k is s s a b -> b -> m ()
assign' Optic k is s s a b
o = Optic k is s s a b -> (a -> b) -> m ()
forall k s (m :: * -> *) (is :: IxList) a b.
(Is k A_Setter, MonadState s m) =>
Optic k is s s a b -> (a -> b) -> m ()
modifying' Optic k is s s a b
o ((a -> b) -> m ()) -> (b -> a -> b) -> b -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a -> b
forall a b. a -> b -> a
const
{-# INLINE assign' #-}
use
:: (Is k A_Getter, MonadState s m)
=> Optic' k is s a
-> m a
use :: Optic' k is s a -> m a
use Optic' k is s a
o = (s -> a) -> m a
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Optic' k is s a -> s -> a
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Optic' k is s a
o)
{-# INLINE use #-}
preuse
:: (Is k An_AffineFold, MonadState s m)
=> Optic' k is s a
-> m (Maybe a)
preuse :: Optic' k is s a -> m (Maybe a)
preuse Optic' k is s a
o = (s -> Maybe a) -> m (Maybe a)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Optic' k is s a -> s -> Maybe a
forall k (is :: IxList) s a.
Is k An_AffineFold =>
Optic' k is s a -> s -> Maybe a
preview Optic' k is s a
o)
{-# INLINE preuse #-}