lens 1.0.2 → 1.0.3
raw patch · 2 files changed
+23/−15 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- lens.cabal +1/−1
- src/Control/Lens.hs +22/−14
lens.cabal view
@@ -1,6 +1,6 @@ name: lens category: Data, Lenses-version: 1.0.2+version: 1.0.3 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE
src/Control/Lens.hs view
@@ -86,10 +86,10 @@ -- ** Setting Values , adjust , set- , (^~), (+~), (-~), (*~), (//~), (||~), (&&~), (|~), (&~), (%~)+ , (^~), (+~), (-~), (*~), (//~), (||~), (&&~), (|~), (&~), (%~), (<>~) -- ** Setting State- , (^=), (+=), (-=), (*=), (//=), (||=), (&&=), (|=), (&=), (%=)+ , (^=), (+=), (-=), (*=), (//=), (||=), (&&=), (|=), (&=), (%=), (<>=) -- * Getters and Folds , Getter@@ -145,6 +145,7 @@ , traverseDynamic , traverseException , traverseElement, traverseElements+ , traverseValue -- * Transforming Traversals , elementOf@@ -186,8 +187,8 @@ import Data.Word (Word8) infixl 8 ^.-infixr 4 ^~, +~, *~, -~, //~, &&~, ||~, &~, |~, %~, %%~-infix 4 ^=, +=, *=, -=, //=, &&=, ||=, &=, |=, %=, %%=+infixr 4 ^~, +~, *~, -~, //~, &&~, ||~, &~, |~, %~, <>~, %%~+infix 4 ^=, +=, *=, -=, //=, &&=, ||=, &=, |=, %=, <>=, %%= infixr 0 ^$ --------------------------@@ -651,6 +652,10 @@ l &~ n = adjust l (.&. n) {-# INLINE (&~) #-} +(<>~) :: Monoid c => Setter a b c c -> c -> a -> b+l <>~ n = adjust l (<> n)+{-# INLINE (<>~) #-}+ --------------- -- Getters ---------------@@ -923,6 +928,7 @@ l %= f = modify (l %~ f) {-# INLINE (%=) #-} + -- | Modify the target(s) of a 'Simple' 'Lens', 'Setter' or 'Traversal' by adding a value -- -- Example:@@ -969,6 +975,10 @@ l |= b = modify (l |~ b) {-# INLINE (|=) #-} +(<>=) :: (MonadState a m, Monoid b) => Simple Setter a b -> b -> m ()+l <>= b = modify (l <>~ b)+{-# INLINE (<>=) #-}+ -------------------------- -- Folds --------------------------@@ -1030,16 +1040,6 @@ takingWhile p l f = Const . foldrOf l (\a r -> if p a then getConst (f a) `mappend` r else mempty) mempty {-# INLINE takingWhile #-} -{--taking :: Monoid m => Int -> Getting [c] a b c d -> Getting m a b c d-taking n l f = foldMap (getConst . f) . take n . toListOf l-{-# INLINE taking #-}--dropping :: Monoid m => Int -> Getting [c] a b c d -> Getting m a b c d-dropping n l f = foldMap (getConst . f) . drop n . toListOf l-{-# INLINE dropping #-}--}- -- | Obtain a 'Fold' by dropping elements from another 'Fold', 'Lens', 'Getter' or 'Traversal' while a predicate holds. -- -- > dropWhile p = toListOf (droppingWhile p folded)@@ -1777,6 +1777,13 @@ step _ r = r {-# INLINE traverseBits #-} +-- | This provides a 'Traversal' that checks a predicate on a key before allowing you to traverse into a value.+traverseValue :: (k -> Bool) -> Simple Traversal (k, v) v+traverseValue p f kv@(k,v)+ | p k = (,) k <$> f v+ | otherwise = pure kv+{-# INLINE traverseValue #-}+ ------------------------------------------------------------------------------ -- Cloning Lenses ------------------------------------------------------------------------------@@ -1796,6 +1803,7 @@ --------------------------- -- Constructing Traversals ---------------------------+ -- | Yields a 'Traversal' of the nth element of another 'Traversal' --