module Data.Lens
( module Data.Lens.Common
, access
, (~=), (!=)
, (%=), (!%=)
, (%%=), (!%%=)
, (+=), (!+=)
, (-=), (!-=)
, (*=), (!*=)
, (//=), (!/=)
, (&&=), (!&&=)
, (||=), (!||=)
) where
import Control.Comonad.Trans.Store
import Control.Monad.State
import Data.Functor.Identity
import Data.Lens.Common
access :: MonadState a m => Lens a b -> m b
access (Lens f) = gets (pos . f)
infixr 4 ~=, !=
(~=), (!=) :: MonadState a m => Lens a b -> b -> m b
Lens f ~= b = do
modify (peek b . f)
return b
Lens f != b = do
StoreT (Identity h) _ <- gets f
put (h $! b)
return b
infixr 4 %=, !%=
(%=), (!%=) :: MonadState a m => Lens a b -> (b -> b) -> m b
Lens f %= g = do
StoreT (Identity h) b <- gets f
let b' = g b
put (h b')
return b'
Lens f !%= g = do
StoreT (Identity h) b <- gets f
let b' = g b
b' `seq` put (h b')
return b'
infixr 4 %%=, !%%=
(%%=), (!%%=) :: MonadState a m => Lens a b -> (b -> (c, b)) -> m c
Lens f %%= g = do
StoreT (Identity h) b <- gets f
let (c, b') = g b
put (h b')
return c
Lens f !%%= g = do
StoreT (Identity h) b <- gets f
let (c, b') = g b
b' `seq` put (h b')
return c
infixr 4 +=, !+=, -=, !-=, *=, !*=
(+=), (!+=), (-=), (!-=), (*=), (!*=) :: (MonadState a m, Num b) => Lens a b -> b -> m b
f += b = f %= (+ b)
f -= b = f %= subtract b
f *= b = f %= (* b)
f !+= b = f !%= (+ b)
f !-= b = f !%= subtract b
f !*= b = f !%= (* b)
infixr 4 //=, !/=
(//=), (!/=) :: (MonadState a m, Fractional b) => Lens a b -> b -> m b
f //= b = f %= (/ b)
f !/= b = f !%= (/ b)
infixr 4 &&=, !&&=, ||=, !||=
(&&=), (||=), (!&&=), (!||=) :: MonadState a m => Lens a Bool -> Bool -> m Bool
f &&= b = f %= (&& b)
f ||= b = f %= (|| b)
f !&&= b = f !%= (&& b)
f !||= b = f !%= (|| b)