packages feed

data-lens-light 0.1.0.2 → 0.1.1

raw patch · 3 files changed

+39/−3 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Lens.Light: class MonadStateT t
+ Data.Lens.Light: zoom :: (MonadStateT stateT, MonadState s (stateT s m), MonadTrans (stateT s), Monad m) => Lens s s' -> stateT s' m a -> stateT s m a

Files

CHANGELOG.md view
@@ -1,6 +1,11 @@ Changes ======= +Version 0.1.1+-------------++Add `zoom`+ Version 0.1.0.2 --------------- 
data-lens-light.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                data-lens-light-version:             0.1.0.2+version:             0.1.1 synopsis:            Simple lenses, minimum dependencies description:         See <https://github.com/feuerbach/data-lens-light/blob/master/README.md> homepage:            https://github.com/feuerbach/data-lens-light
src/Data/Lens/Light/State.hs view
@@ -1,14 +1,19 @@-{-# LANGUAGE CPP #-}+{-# LANGUAGE CPP, MultiParamTypeClasses, FlexibleInstances #-} module Data.Lens.Light.State   ( access   , (~=)   , (!=)   , (%=)   , (!%=)+  , zoom+  , MonadStateT   )   where -import Control.Monad.State+import Control.Monad.State.Class+import qualified Control.Monad.State.Strict as Strict+import qualified Control.Monad.State as Lazy+import Control.Monad.Trans import Data.Lens.Light.Core  -- | Get the value of a lens into state@@ -42,3 +47,29 @@ l !%= f = modify' $ modL' l f  infixr 4 %=, !%=++-- | The purpose of this class is to abstract the difference between the+-- lazy and strict state monads, so that 'zoom' can work with either of+-- them.+class MonadStateT t where+  runStateT :: t s m a -> s -> m (a, s)++instance MonadStateT Strict.StateT where runStateT = Strict.runStateT+instance MonadStateT Lazy.StateT where runStateT = Lazy.runStateT++-- | Run a stateful computation with a smaller state inside another+-- computation with a bigger state.+zoom+  :: ( MonadStateT stateT+     , MonadState s (stateT s m)+     , MonadTrans (stateT s)+     , Monad m+     )+  => Lens s s'+  -> stateT s' m a+  -> stateT s m a+zoom l a = do+  s <- get+  (r, s') <- lift $ runStateT a (s ^. l)+  modify' $ setL l s'+  return r