microlens 0.4.13.1 → 0.4.14.0
raw patch · 3 files changed
+123/−16 lines, 3 files
Files
- CHANGELOG.md +9/−0
- microlens.cabal +18/−16
- src/Lens/Micro.hs +96/−0
CHANGELOG.md view
@@ -1,3 +1,12 @@+# 0.4.14.0++* Add optics `mapMOf`, `rewriteMOf`, `transformMOf`, `anyOf`, `allOf`, `noneOf`, `foldMapOf`, and `cosmosOf`.++# 0.4.13.1++* [#161](https://github.com/stevenfontanella/microlens/pull/161) Fix GHC 9.4 warning for using `~` without TypeOperators+* [#162](https://github.com/stevenfontanella/microlens/pull/162) Fix GHC warning for depending on StarIsType+ # 0.4.13.0 * Added `_Show`, `worded`, and `lined`.
microlens.cabal view
@@ -1,12 +1,12 @@ name: microlens-version: 0.4.13.1+version: 0.4.14.0 synopsis: A tiny lens library with no dependencies description: NOTE: If you're writing an app, you probably want <http://hackage.haskell.org/package/microlens-platform microlens-platform> – it has the most features. <http://hackage.haskell.org/package/microlens microlens> is intended more for library writers who want a tiny lens library (after all, lenses are pretty useful for everything, not just for updating records!). . This library 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. .- There's a longer readme <https://github.com/monadfix/microlens#readme on Github>. It has a migration guide for lens users, a description of other packages in the family, a discussion of other lens libraries you could use instead, and so on.+ There's a longer readme <https://github.com/stevenfontanella/microlens#readme on Github>. It has a migration guide for lens users, a description of other packages in the family, a discussion of other lens libraries you could use instead, and so on. . Here are some usecases for this library: .@@ -33,30 +33,32 @@ license-file: LICENSE author: Edward Kmett, Artyom Kazak maintainer: Steven Fontanella <steven.fontanella@gmail.com>-homepage: http://github.com/monadfix/microlens-bug-reports: http://github.com/monadfix/microlens/issues+homepage: http://github.com/stevenfontanella/microlens+bug-reports: http://github.com/stevenfontanella/microlens/issues -- copyright: category: Data, Lenses build-type: Simple extra-source-files: CHANGELOG.md cabal-version: >=1.10-tested-with: GHC==7.6.3- GHC==7.8.4- GHC==7.10.3- GHC==8.0.2- GHC==8.2.2- GHC==8.4.4- GHC==8.6.5- GHC==8.8.4- GHC==8.10.7+tested-with:+ GHC==9.12.1+ GHC==9.10.1+ GHC==9.8.4+ GHC==9.6.6+ GHC==9.4.8+ GHC==9.2.8 GHC==9.0.2- GHC==9.2.5- GHC==9.4.3+ GHC==8.10.7+ GHC==8.8.4+ GHC==8.6.5+ GHC==8.4.4+ GHC==8.2.2+ GHC==8.0.2 source-repository head type: git- location: git://github.com/monadfix/microlens.git+ location: https://github.com/stevenfontanella/microlens.git library exposed-modules: Lens.Micro
src/Lens/Micro.hs view
@@ -21,6 +21,7 @@ * <http://hackage.haskell.org/package/microlens-ghc microlens-ghc> – everything in microlens + instances to make @each@\/@at@\/@ix@ usable with arrays, @ByteString@, and containers * <http://hackage.haskell.org/package/microlens-platform microlens-platform> – microlens-ghc + microlens-mtl + microlens-th + instances for @Text@, @Vector@, and @HashMap@ * <http://hackage.haskell.org/package/microlens-contra microlens-contra> – @Fold@ and @Getter@ that are exact copies of types in lens+* <http://hackage.haskell.org/package/microlens-pro microlens-pro> – microlens-platform + @Iso@ and @Prism@ Unofficial: @@ -45,8 +46,11 @@ (?~), (<%~), (<<%~), (<<.~), mapped,+ mapMOf, rewriteOf,+ rewriteMOf, transformOf,+ transformMOf, -- * Getter: extracts a value from a structure -- $getters-note@@ -66,6 +70,10 @@ has, folded, folding,+ foldMapOf,+ anyOf,+ allOf,+ noneOf, -- * Lens: a combined getter-and-setter -- $lenses-note@@ -94,6 +102,7 @@ _head, _tail, _init, _last, mapAccumLOf, worded, lined,+ cosmosOf, -- * Prism: a traversal iterating over at most 1 element -- $prisms-note@@ -459,6 +468,16 @@ {-# INLINE mapped #-} {- |+Map each element of a structure targeted by a Lens to a monadic action, evaluate these actions from left to right, and collect the results.++>>> mapMOf both (\x -> [x, x + 1]) (1,3)+[(1,3),(1,4),(2,3),(2,4)]+-}+mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t+mapMOf = coerce+{-# INLINE mapMOf #-}++{- | This is a version of ('%~') which modifies the structure and returns it along with the new value: >>> (1, 2) & _1 <%~ negate@@ -532,6 +551,17 @@ {-# INLINE rewriteOf #-} {- |+Rewrite by applying a monadic rule everywhere you can. Ensures that the rule cannot be applied anywhere in the result.+-}+rewriteMOf+ :: Monad m+ => LensLike (WrappedMonad m) a b a b -> (b -> m (Maybe a)) -> a -> m b+rewriteMOf l f = go+ where+ go = transformMOf l (\x -> f x >>= maybe (return x) go)+{-# INLINE rewriteMOf #-}++{- | Transform every element by recursively applying a given 'ASetter' in a bottom-up manner. @since 0.4.11@@ -541,6 +571,16 @@ go = f . over l go {-# INLINE transformOf #-} +{- |+Transform every element by recursively applying a given 'ASetter' in a bottom-up manner with a monadic effect.+-}+transformMOf+ :: Monad m => LensLike (WrappedMonad m) a b a b -> (b -> m b) -> a -> m b+transformMOf l f = go+ where+ go t = mapMOf l go t >>= f+{-# INLINE transformMOf #-}+ -- Getting ----------------------------------------------------------------- {- $getters-note@@ -776,6 +816,51 @@ folding sfa agb = phantom . F.traverse_ agb . sfa {-# INLINE folding #-} +{- |+Returns 'True' if any value returned by a getter (any getter, including lenses,+traversals, and folds) satisfies a predicate.++>>> anyOf each (=='x') ['x','x']+True+>>> anyOf each (=='x') ['x','y']+True+>>> anyOf each (=='x') ['y','y']+False+-}+anyOf :: Getting Any s a -> (a -> Bool) -> s -> Bool+anyOf l f = getAny #. foldMapOf l (Any #. f)+{-# INLINE anyOf #-}++{- |+Returns 'True' if any value returned by a getter (any getter, including lenses,+traversals, and folds) satisfies a predicate.++>>> allOf each (=='x') ['x','x']+True+>>> allOf each (=='x') ['x','y']+False+>>> allOf each (=='x') ['y','y']+False+-}+allOf :: Getting All s a -> (a -> Bool) -> s -> Bool+allOf l f = getAll #. foldMapOf l (All #. f)+{-# INLINE allOf #-}++{- |+Returns 'True' if no value returned by a getter (any getter, including lenses,+traversals, and folds) satisfies a predicate.++>>> noneOf each (=='x') ['x','x']+False+>>> noneOf each (=='x') ['x','y']+False+>>> noneOf each (=='x') ['y','y']+True+-}+noneOf :: Getting Any s a -> (a -> Bool) -> s -> Bool+noneOf l f = not . anyOf l f+{-# INLINE noneOf #-}+ -- Lenses ------------------------------------------------------------------ {- $lenses-note@@ -910,6 +995,8 @@ @ However, it's not possible for microlens to export isomorphisms, because their type depends on @<http://hackage.haskell.org/package/profunctors/docs/Data-Profunctor.html#t:Profunctor Profunctor>@, which resides in the <http://hackage.haskell.org/package/profunctors profunctors> library, which is a somewhat huge dependency. So, all isomorphisms included here are lenses instead (and thus you can't use them in the opposite direction).++Should you find yourself in need of true lens-compatible isos, consider <https://hackage.haskell.org/package/microlens-pro microlens-pro>, or just lens :^). -} {- |@@ -1296,6 +1383,13 @@ lined f = fmap (intercalate "\n") . traverse f . lines {-# INLINE lined #-} +{- |+Given a Traversal that knows how to locate immediate children, traverse all of the transitive descendants of a node, including itself.+-}+cosmosOf :: Traversal a t a t -> Traversal a t a b'+cosmosOf d f s = f s *> d (cosmosOf d f) s+{-# INLINE cosmosOf #-}+ -- Prisms ------------------------------------------------------------------ {- $prisms-note@@ -1311,6 +1405,8 @@ @ However, it's not possible for microlens to export prisms, because their type depends on @<http://hackage.haskell.org/package/profunctors/docs/Data-Profunctor.html#t:Choice Choice>@ from <http://hackage.haskell.org/package/profunctors profunctors>. So, all prisms included here are traversals instead (and you can't reverse them).++Should you find yourself in need of true lens-compatible prisms, consider <https://hackage.haskell.org/package/microlens-pro microlens-pro>, or just lens :^). -} {- |