{-# LANGUAGE CPP #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Trustworthy #-}
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
module Lens.Micro.Mtl
(
view, preview,
use, preuse,
(%=), modifying,
(.=), assign,
(?=),
(<~),
(&~),
(+=), (-=), (*=), (//=),
(<%=), (<.=), (<?=),
(<<%=), (<<.=),
zoom,
magnify,
)
where
import Control.Applicative
import Data.Monoid
import Control.Monad.Reader as Reader
import Control.Monad.State as State
import Lens.Micro
import Lens.Micro.Internal
import Lens.Micro.Mtl.Internal
view :: MonadReader s m => Getting a s a -> m a
view :: forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting a s a
l = forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
Reader.asks (forall {k} a (b :: k). Const a b -> a
getConst forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. Getting a s a
l forall {k} a (b :: k). a -> Const a b
Const)
{-# INLINE view #-}
preview :: MonadReader s m => Getting (First a) s a -> m (Maybe a)
preview :: forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview Getting (First a) s a
l = forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
Reader.asks (forall a. First a -> Maybe a
getFirst forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. forall r s a. Getting r s a -> (a -> r) -> s -> r
foldMapOf Getting (First a) s a
l (forall a. Maybe a -> First a
First forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. forall a. a -> Maybe a
Just))
{-# INLINE preview #-}
use :: MonadState s m => Getting a s a -> m a
use :: forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting a s a
l = forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
State.gets (forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting a s a
l)
{-# INLINE use #-}
preuse :: MonadState s m => Getting (First a) s a -> m (Maybe a)
preuse :: forall s (m :: * -> *) a.
MonadState s m =>
Getting (First a) s a -> m (Maybe a)
preuse Getting (First a) s a
l = forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
State.gets (forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview Getting (First a) s a
l)
{-# INLINE preuse #-}
(&~) :: s -> State s a -> s
s
s &~ :: forall s a. s -> State s a -> s
&~ State s a
l = forall s a. State s a -> s -> s
execState State s a
l s
s
{-# INLINE (&~) #-}
infixl 1 &~
(.=) :: MonadState s m => ASetter s s a b -> b -> m ()
ASetter s s a b
l .= :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= b
x = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
State.modify (ASetter s s a b
l forall s t a b. ASetter s t a b -> b -> s -> t
.~ b
x)
{-# INLINE (.=) #-}
infix 4 .=
assign :: MonadState s m => ASetter s s a b -> b -> m ()
assign :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
assign ASetter s s a b
l b
x = ASetter s s a b
l forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= b
x
{-# INLINE assign #-}
(?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m ()
ASetter s s a (Maybe b)
l ?= :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a (Maybe b) -> b -> m ()
?= b
b = ASetter s s a (Maybe b)
l forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= forall a. a -> Maybe a
Just b
b
{-# INLINE (?=) #-}
infix 4 ?=
(<~) :: MonadState s m => ASetter s s a b -> m b -> m ()
ASetter s s a b
l <~ :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> m b -> m ()
<~ m b
mb = m b
mb forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ASetter s s a b
l forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.=)
{-# INLINE (<~) #-}
infixr 2 <~
(%=) :: (MonadState s m) => ASetter s s a b -> (a -> b) -> m ()
ASetter s s a b
l %= :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= a -> b
f = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
State.modify (ASetter s s a b
l forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ a -> b
f)
{-# INLINE (%=) #-}
infix 4 %=
modifying :: (MonadState s m) => ASetter s s a b -> (a -> b) -> m ()
modifying :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
modifying ASetter s s a b
l a -> b
f = ASetter s s a b
l forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= a -> b
f
{-# INLINE modifying #-}
(+=) :: (MonadState s m, Num a) => ASetter s s a a -> a -> m ()
ASetter s s a a
l += :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
ASetter s s a a -> a -> m ()
+= a
x = ASetter s s a a
l forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (forall a. Num a => a -> a -> a
+a
x)
{-# INLINE (+=) #-}
infix 4 +=
(-=) :: (MonadState s m, Num a) => ASetter s s a a -> a -> m ()
ASetter s s a a
l -= :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
ASetter s s a a -> a -> m ()
-= a
x = ASetter s s a a
l forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (forall a. Num a => a -> a -> a
subtract a
x)
{-# INLINE (-=) #-}
infix 4 -=
(*=) :: (MonadState s m, Num a) => ASetter s s a a -> a -> m ()
ASetter s s a a
l *= :: forall s (m :: * -> *) a.
(MonadState s m, Num a) =>
ASetter s s a a -> a -> m ()
*= a
x = ASetter s s a a
l forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (forall a. Num a => a -> a -> a
*a
x)
{-# INLINE (*=) #-}
infix 4 *=
(//=) :: (MonadState s m, Fractional a) => ASetter s s a a -> a -> m ()
ASetter s s a a
l //= :: forall s (m :: * -> *) a.
(MonadState s m, Fractional a) =>
ASetter s s a a -> a -> m ()
//= a
x = ASetter s s a a
l forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (forall a. Fractional a => a -> a -> a
/a
x)
{-# INLINE (//=) #-}
infix 4 //=
(<%=) :: MonadState s m => LensLike ((,) b) s s a b -> (a -> b) -> m b
LensLike ((,) b) s s a b
l <%= :: forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= a -> b
f = LensLike ((,) b) s s a b
l forall s (m :: * -> *) r a b.
MonadState s m =>
LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r
%%= (\b
a -> (b
a, b
a)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f
{-# INLINE (<%=) #-}
infix 4 <%=
(<<%=) :: MonadState s m => LensLike ((,) a) s s a b -> (a -> b) -> m a
LensLike ((,) a) s s a b
l <<%= :: forall s (m :: * -> *) a b.
MonadState s m =>
LensLike ((,) a) s s a b -> (a -> b) -> m a
<<%= a -> b
f = LensLike ((,) a) s s a b
l forall s (m :: * -> *) r a b.
MonadState s m =>
LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r
%%= (\a
a -> (a
a, a -> b
f a
a))
{-# INLINE (<<%=) #-}
infix 4 <<%=
(<<.=) :: MonadState s m => LensLike ((,) a) s s a b -> b -> m a
LensLike ((,) a) s s a b
l <<.= :: forall s (m :: * -> *) a b.
MonadState s m =>
LensLike ((,) a) s s a b -> b -> m a
<<.= b
b = LensLike ((,) a) s s a b
l forall s (m :: * -> *) r a b.
MonadState s m =>
LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r
%%= (\a
a -> (a
a, b
b))
{-# INLINE (<<.=) #-}
infix 4 <<.=
(<.=) :: MonadState s m => LensLike ((,) b) s s a b -> b -> m b
LensLike ((,) b) s s a b
l <.= :: forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> b -> m b
<.= b
b = LensLike ((,) b) s s a b
l forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= forall a b. a -> b -> a
const b
b
{-# INLINE (<.=) #-}
infix 4 <.=
(<?=) :: MonadState s m => LensLike ((,) b) s s a (Maybe b) -> b -> m b
LensLike ((,) b) s s a (Maybe b)
l <?= :: forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a (Maybe b) -> b -> m b
<?= b
b = LensLike ((,) b) s s a (Maybe b)
l forall s (m :: * -> *) r a b.
MonadState s m =>
LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r
%%= forall a b. a -> b -> a
const (b
b, forall a. a -> Maybe a
Just b
b)
{-# INLINE (<?=) #-}
infix 4 <?=
(%%=) :: MonadState s m => LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r
#if MIN_VERSION_mtl(2,1,1)
LensLike ((,) r) s s a b
l %%= :: forall s (m :: * -> *) r a b.
MonadState s m =>
LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r
%%= a -> (r, b)
f = forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
State.state (LensLike ((,) r) s s a b
l a -> (r, b)
f)
#else
l %%= f = do
(r, s) <- State.gets (l f)
State.put s
return r
#endif
{-# INLINE (%%=) #-}
infix 4 %%=