microlens 0.4.3.0 → 0.4.4.0
raw patch · 3 files changed
+22/−2 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Lens.Micro: mapAccumLOf :: LensLike (State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
Files
- CHANGELOG.md +4/−0
- microlens.cabal +2/−2
- src/Lens/Micro.hs +16/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.4.4.0++* Added `mapAccumLOf`.+ # 0.4.3.0 * Added `?~`.
microlens.cabal view
@@ -1,5 +1,5 @@ name: microlens-version: 0.4.3.0+version: 0.4.4.0 synopsis: A tiny part of the lens library with no dependencies description: This is an extract from <http://hackage.haskell.org/package/lens lens> (with no dependencies). It's not a toy lenses library, unsuitable for “real world”, but merely a small one. It is compatible with lens, and should have same performance. It also has better documentation.@@ -12,7 +12,7 @@ . Don't use this library: .- * if you need @Iso@s, @Prism@s, indexed traversals, or actually anything else which isn't defined here+ * if you need @Iso@s, @Prism@s, indexed traversals, or actually anything else which isn't defined here (tho some indexed functions are available elsewhere – containers and vector provide them for their types, and <http://hackage.haskell.org/package/ilist ilist> provides indexed functions for lists) . * if you want a library with a clean, understandable implementation (in which case you're looking for <http://hackage.haskell.org/package/lens-simple lens-simple>) .
src/Lens/Micro.hs view
@@ -68,6 +68,7 @@ each, ix, _head, _tail, _init, _last,+ mapAccumLOf, -- * Prism: a traversal iterating over at most 1 element -- $prisms-note@@ -88,6 +89,7 @@ import Data.Functor.Identity import Data.Monoid import Data.Maybe+import Data.Tuple import qualified Data.Foldable as F import Unsafe.Coerce @@ -905,6 +907,20 @@ _last :: Snoc s s a a => Traversal' s a _last = _Snoc._2 {-# INLINE _last #-}+++{- |+This generalizes 'Data.Traversable.mapAccumL' to an arbitrary 'Traversal'. (Note that it doesn't work on folds, only traversals.)++@+'mapAccumL' ≡ 'mapAccumLOf' 'traverse'+@+-}+mapAccumLOf :: LensLike (State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)+mapAccumLOf l f acc0 s = swap (runState (l g s) acc0)+ where+ g a = state $ \acc -> swap (f acc a)+{-# INLINE mapAccumLOf #-} -- Prisms ------------------------------------------------------------------