module MonadVar.Lens
( (./)
, effectful
, (.!)
, _VarM
, _Var
) where
import MonadVar
import Data.Functor.Identity
import Data.Functor.Const
import Data.Functor.Compose
infixl 8 ^.
infixr 9 ./, .!
type LensLike f s t a b = (a -> f b) -> s -> f t
type Lens s t a b = forall f. Functor f => LensLike f s t a b
type ASetter s t a b = LensLike Identity s t a b
(^.) :: s -> LensLike (Const a) s t a b -> a
s ^. _L = getConst (_L Const s)
_Of :: (s -> a) -> LensLike f s b a b
_Of f g = g . f
(./)
:: LensLike (Const s) v x s y
-> LensLike f s t a b
-> LensLike f v t a b
_L ./ _M = _Of (^. _L) . _M
effectful :: Functor f => Lens s t a b -> Lens s (f t) a (f b)
effectful _L f = getCompose . _L (Compose . f)
(.!)
:: (Functor f, Functor g)
=> Lens v w s t
-> LensLike g s (f t) a b
-> LensLike g v (f w) a b
_L .! _M = effectful _L . _M
_VarM :: forall m n v a. MonadMutateM_ m n v => ASetter (v a) (n ()) a (m a)
_VarM f v = Identity . mutateM_ v $ runIdentity . f
_Var :: forall m v a. MonadMutate_ m v => ASetter (v a) (m ()) a a
_Var f v = Identity . mutate_ v $ runIdentity . f