packages feed

fclabels 1.1.4.3 → 1.1.5

raw patch · 3 files changed

+21/−7 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Label.PureM: modifyAndGet :: MonadState s m => (s :-> a) -> (a -> (b, a)) -> m b

Files

fclabels.cabal view
@@ -1,5 +1,5 @@ Name:          fclabels-Version:       1.1.4.3+Version:       1.1.5 Author:        Sebastiaan Visser, Erik Hesselink, Chris Eidhof, Sjoerd Visscher                with lots of help and feedback from others. Synopsis:      First class accessor labels.@@ -20,14 +20,14 @@                .                See the "Data.Label.Maybe" module for the use of partial labels.                .-               > 1.1.4.2 -> 1.1.4.3-               >   - Make compilable against template haskell 2.8.-               >     Thanks to mgsloan for the pull request.+               > 1.1.4.3 -> 1.1.5+               >   - Added `modifyAndGet` helper function.+               >     Thanks to Nikita Volkov.  Maintainer:    Sebastiaan Visser <code@fvisser.nl> License:       BSD3 License-File:  LICENSE-Category:      Data+Category:      Data, Lenses Cabal-Version: >= 1.6 Build-Type:    Simple 
src/Data/Label.hs view
@@ -100,7 +100,9 @@ >import Control.Applicative  >ageAndCity :: Person :-> (Int, String)->ageAndCity = Lens $ (,) <$> fst `for` age <*> snd `for` city . place+>ageAndCity = Lens $+>  (,) <$> fst `for` age+>      <*> snd `for` city . place  Because the applicative type class on its own is not very capable of expressing bidirectional relations, which we need for our lenses, the actual instance is@@ -130,7 +132,7 @@ -- functions. Just like lenses, bijections can be composed using the -- "Control.Category" type class. Bijections can be used to change the type of -- a lens. The `Iso` type class, which can be seen as a bidirectional functor,--- can be used to apply lenses to lenses.+-- can be used to apply bijections to lenses. --  -- For example, when we want to treat the age of a person as a string we can do -- the following:
src/Data/Label/PureM.hs view
@@ -5,6 +5,7 @@   gets , puts , modify+, modifyAndGet , (=:) , (=.) @@ -14,6 +15,7 @@ ) where +import Control.Monad import Data.Label.Pure ((:->)) import qualified Control.Monad.Reader as M import qualified Control.Monad.State  as M@@ -57,4 +59,14 @@  local :: M.MonadReader r m => (r :-> b) -> (b -> b) -> m a -> m a local l f = M.local (L.modify l f)++-- | Modify a value with a function somewhere in the state, pointed to by the+-- specified lens. Additionally return a separate value based on the+-- modification.++modifyAndGet :: M.MonadState s m => (s :-> a) -> (a -> (b, a)) -> m b+modifyAndGet l f =+  do (b, a) <- f `liftM` gets l+     puts l a+     return b