lens 1.0 → 1.0.1
raw patch · 3 files changed
+55/−2 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Lens: backwards :: LensLike (Backwards f) a b c d -> LensLike f a b c d
+ Control.Lens: type SimpleLens a b = Lens a a b b
+ Control.Lens: type SimpleLensLike f a b = LensLike f a a b b
+ Control.Lens: type SimpleSetter a b = Lens a a b b
+ Control.Lens: type SimpleTraversal a b = Traversal a a b b
+ Control.Lens.Internal: Backwards :: f a -> Backwards f a
+ Control.Lens.Internal: getBackwards :: Backwards f a -> f a
+ Control.Lens.Internal: instance Applicative f => Applicative (Backwards f)
+ Control.Lens.Internal: instance Functor f => Functor (Backwards f)
+ Control.Lens.Internal: newtype Backwards f a
Files
- lens.cabal +1/−1
- src/Control/Lens.hs +44/−1
- src/Control/Lens/Internal.hs +10/−0
lens.cabal view
@@ -1,6 +1,6 @@ name: lens category: Data, Lenses-version: 1.0+version: 1.0.1 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE
src/Control/Lens.hs view
@@ -51,6 +51,9 @@ , LensLike , Traversal , Simple+ , SimpleLens+ , SimpleTraversal+ , SimpleLensLike -- ** Constructing Lenses , lens@@ -74,6 +77,7 @@ -- * Setters , Setter+ , SimpleSetter , sets , mapped @@ -140,6 +144,7 @@ -- * Transforming Traversals , elementOf , elementsOf+ , backwards -- * Cloning Lenses , clone@@ -220,8 +225,27 @@ -- -- > imaginary :: Simple Lens (Complex a) a -- > traverseHead :: Simple Traversal [a] a+--+-- Note: If you plan to use this alias in your code, you may have to turn on+--+-- > {-# LANGUAGE LiberalTypeSynonyms #-} type Simple f a b = f a a b b +-- | This alias is supplied for those who don't want to use @{-# LANGUAGE LiberalTypeSynonyms #-}@ and 'Simple'+--+-- > 'SimpleTraversal' = 'Simple' 'Traversal'+type SimpleTraversal a b = Traversal a a b b++-- | This alias is supplied for those who don't want to use @{-# LANGUAGE LiberalTypeSynonyms #-}@ and 'Simple'+--+-- > 'SimpleLens' = 'Simple' 'Lens'+type SimpleLens a b = Lens a a b b++-- | This alias is supplied for those who don't want to use @{-# LANGUAGE LiberalTypeSynonyms #-}@ and 'Simple'+--+-- > 'SimpleLensLike' f = 'Simple' ('LensLike' f)+type SimpleLensLike f a b = LensLike f a a b b+ -------------------------- -- Constructing Lenses --------------------------@@ -411,7 +435,7 @@ sequenceOf l = unwrapMonad . l WrapMonad {-# INLINE sequenceOf #-} --- | This generalizes 'transpose' to an arbitrary 'Traversal'.+-- | This generalizes 'Data.List.transpose' to an arbitrary 'Traversal'. -- -- > transpose = transposeOf traverse --@@ -442,6 +466,11 @@ -- > type Setter a b c d = LensLike Identity a b c d type Setter a b c d = (c -> Identity d) -> a -> Identity b +-- | This alias is supplied for those who don't want to bother using {-# LANGUAGE LiberalTypeSynonyms #-} and 'Simple'.+--+-- > 'SimpleSetter ' = 'Simple' 'Setter'+type SimpleSetter a b = Lens a a b b+ -- | This setter can be used to map over all of the values in a 'Functor'. -- -- > fmap = adjust mapped@@ -1498,6 +1527,7 @@ traverseDynamic f dyn = case fromDynamic dyn of Just a -> toDyn <$> f a Nothing -> pure dyn+{-# INLINE traverseDynamic #-} -- | -- Traverse the strongly typed 'Exception' contained in 'SomeException' where the type of your function matches@@ -1508,6 +1538,7 @@ traverseException f e = case fromException e of Just a -> toException <$> f a Nothing -> pure e+{-# INLINE traverseException #-} -- | Provides ad hoc overloading for 'traverseByteString' class TraverseByteString t where@@ -1610,6 +1641,7 @@ hasBit n = complementBit b n /= b -- test to make sure that complementing this bit actually changes the value step (n,True) r = setBit r n step _ r = r+{-# INLINE traverseBits #-} ------------------------------------------------------------------------------ -- Cloning Lenses@@ -1636,6 +1668,7 @@ -- > traverseHead = elementOf traverse 0 elementOf :: Applicative f => LensLike (AppliedState f) a b c c -> Int -> LensLike f a b c c elementOf l = elementsOf l . (==)+{-# INLINE elementOf #-} -- | A 'Traversal' of the elements in another 'Traversal' where their positions in that 'Traversal' satisfy a predicate --@@ -1643,3 +1676,13 @@ elementsOf :: Applicative f => LensLike (AppliedState f) a b c c -> (Int -> Bool) -> LensLike f a b c c elementsOf l p f ta = fst (runAppliedState (l go ta) 0) where go a = AppliedState $ \i -> (if p i then f a else pure a, i + 1)+{-# INLINE elementsOf #-}++-- | This allows you to 'traverse' the elements of a 'Traversal' in the opposite order.+--+-- Note: 'reversed' is similar, but is able to accept a 'Fold' (or 'Getter') and produce a 'Fold' (or 'Getter').+--+-- This requires at least a 'Traversal' (or 'Lens') and can produce a 'Traversal' (or 'Lens') in turn.+backwards :: LensLike (Backwards f) a b c d -> LensLike f a b c d+backwards l f = getBackwards . l (Backwards . f)+{-# INLINE backwards #-}
src/Control/Lens/Internal.hs view
@@ -21,6 +21,7 @@ , Traversed(..) , Action(..) , AppliedState(..)+ , Backwards(..) , Min(..) , getMin , Max(..)@@ -111,3 +112,12 @@ getMax :: Max a -> Maybe a getMax NoMax = Nothing getMax (Max a) = Just a++newtype Backwards f a = Backwards { getBackwards :: f a }++instance Functor f => Functor (Backwards f) where+ fmap f (Backwards as) = Backwards (fmap f as)++instance Applicative f => Applicative (Backwards f) where+ pure = Backwards . pure+ Backwards f <*> Backwards a = Backwards (flip id <$> a <*> f)