packages feed

microlens-mtl 0.1.3.1 → 0.1.4.0

raw patch · 4 files changed

+51/−14 lines, 4 filesdep ~microlensPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: microlens

API changes (from Hackage documentation)

+ Lens.Micro.Mtl: preview :: MonadReader s m => Getting (First a) s a -> m (Maybe a)

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.1.4.0++* Added `preview` (a synonym for (`^?`)).+* Bumped microlens version again.+ # 0.1.3.1  * Bumped microlens version.
microlens-mtl.cabal view
@@ -1,9 +1,10 @@ name:                microlens-mtl-version:             0.1.3.1+version:             0.1.4.0 synopsis:            microlens support for Reader/Writer/State from mtl description:-  This package contains functions (like 'view' or '+=') which work   -  on 'MonadReader', 'MonadWriter', and 'MonadState' from the mtl package.+  This package contains functions (like 'view' or '+=') which work on 'MonadReader', 'MonadWriter', and 'MonadState' from the mtl package.+  .+  This package is a part of the <http://hackage.haskell.org/package/microlens microlens> family; see the readme <https://github.com/aelve/microlens#readme on Github>. license:             BSD3 license-file:        LICENSE author:              Artyom@@ -26,7 +27,7 @@   other-modules:       Lens.Micro.Mtl.Zoom   -- other-extensions:       build-depends:       base >=4.5 && <5-                     , microlens ==0.2.*+                     , microlens >=0.2 && <0.4                      , mtl >=2.0.1 && <2.3                      , transformers >=0.2 && <0.5                      , transformers-compat >=0.4 && <1
src/Lens/Micro/Mtl.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE-CPP, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances,@@ -14,6 +13,7 @@ module Lens.Micro.Mtl (   view,+  preview,   use,   zoom,   magnify,@@ -24,6 +24,8 @@   import Control.Applicative+import Data.Monoid+ import Control.Monad.Reader as Reader import Control.Monad.State as State import Control.Monad.Trans.State.Lazy as Lazy@@ -43,9 +45,6 @@ -- Internal modules import Lens.Micro.Mtl.Zoom -#if __GLASGOW_HASKELL__ < 710-import Data.Monoid-#endif  {- | 'view' is a synonym for ('^.'), generalised for 'MonadReader' (we are able to use it instead of ('^.') since functions are instances of the 'MonadReader' class):@@ -68,11 +67,27 @@ {-# INLINE view #-}  {- |-'use' is 'view' which implicitly operates on the state.+'preview' is a synonym for ('^?'), generalised for 'MonadReader' (just like 'view', which is a synonym for ('^.')). -When your state type has lenses generated for it, most of the time you'll be using 'use' instead of 'State.gets'.+>>> preview each [1..5]+Just 1+-}+preview :: MonadReader s m => Getting (First a) s a -> m (Maybe a)+preview l = Reader.asks (getFirst #. foldMapOf l (First #. Just))+{-# INLINE preview #-} +{- |+'use' is 'view' which implicitly operates on the state; for instance, if your state is a record containing a field @foo@, you can write+ @+x \<- 'use' foo+@++to extract @foo@ from the state. In other words, 'use' is the same as 'State.gets', but for getters instead of functions.++The implementation of 'use' is straightforward:++@ 'use' l = 'State.gets' ('view' l) @ -}@@ -86,21 +101,36 @@ infixr 2 `zoom`, `magnify`  {- |-Assign value to the target. This is ('.~') which works in 'MonadState'.+Modify state by “assigning” a value to a part of the state. +This is merely ('.~') which works in 'MonadState':+ @-l '.=' b = 'State.modify' (l '.~' b)+l '.=' x = 'State.modify' (l '.~' x) @ -} (.=) :: MonadState s m => ASetter s s a b -> b -> m ()-l .= b = State.modify (l .~ b)+l .= x = State.modify (l .~ x) {-# INLINE (.=) #-}  {- |-Apply a function to the target. This is ('%~') which works in 'MonadState'.+Modify state by applying a function to a part of the state. An example:  >>> execState (do _1 %= (+1); _2 %= reverse) (1,"hello") (2,"olleh")++Implementation:++@+l '%=' f = 'State.modify' (l '%~' f)+@++There are also a few specialised versions of ('%=') which mimic C operators:++* ('+=') for addition+* ('-=') for substraction+* ('*=') for multiplication+* ('//=') for division (since ('/=') is already taken) -} (%=) :: (MonadState s m) => ASetter s s a b -> (a -> b) -> m () l %= f = State.modify (l %~ f)
src/Lens/Micro/Mtl/Zoom.hs view
@@ -37,6 +37,7 @@ import Data.Monoid #endif + ------------------------------------------------------------------------------ -- Zoomed ------------------------------------------------------------------------------