packages feed

lens 3.8.5 → 3.8.6

raw patch · 10 files changed

+112/−27 lines, 10 filesdep +voiddep ~base

Dependencies added: void

Dependency ranges changed: base

Files

CHANGELOG.markdown view
@@ -1,3 +1,11 @@+3.8.6 [maintenance release]+-----+* Fixed an issue with `DefaultSignatures` being used outside of the appropriate `#ifdef` that caused compilation issues on GHC 7.0.2.+* Generalized the signature of `prism'`+* Added `\_Void` and `only` to `Control.Lens.Prism` and `devoid` to `Control.Lens.Lens`.+* Added `\_Nothing` to `Control.Lens.Prism`.+* Added `devoid` and `united` to `Control.Lens.Lens`.+ 3.8.5 ----- * Fixed more sporadic issues in doctests, caused by carrying flags from `$setup` between modules.
lens.cabal view
@@ -1,6 +1,6 @@ name:          lens category:      Data, Lenses-version:       3.8.5+version:       3.8.6 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -189,7 +189,8 @@     transformers              >= 0.2      && < 0.4,     transformers-compat       >= 0.1      && < 1,     unordered-containers      >= 0.2      && < 0.3,-    vector                    >= 0.9      && < 0.11+    vector                    >= 0.9      && < 0.11,+    void                      >= 0.5      && < 1    exposed-modules:     Control.Exception.Lens@@ -294,7 +295,7 @@   if impl(ghc>=7.2)     cpp-options: -DDEFAULT_SIGNATURES=1 -  ghc-options: -Wall -fwarn-tabs -O2 -fdicts-cheap -funbox-strict-fields+  ghc-options: -Wall -fwarn-tabs -O2 -fdicts-cheap -funbox-strict-fields -fmax-simplifier-iterations=10   hs-source-dirs: src  -- Verify that Template Haskell expansion works
src/Control/Lens/Each.hs view
@@ -2,7 +2,6 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE UndecidableInstances #-}
src/Control/Lens/Iso.hs view
@@ -29,6 +29,7 @@   -- * Consuming Isomorphisms   , from   , cloneIso+  , withIso   -- * Working with isomorphisms   , au   , auf@@ -112,9 +113,13 @@ -- 'from' ('from' l) ≡ l -- @ from :: AnIso s t a b -> Iso b a t s-from k = case runIso k of+from l = case runIso l of   Exchange sa bt -> iso bt sa {-# INLINE from #-}++withIso :: AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r+withIso l k = case runIso l of+  Exchange sa bt -> k sa bt  -- | Convert from 'AnIso' back to any 'Iso'. --
src/Control/Lens/Lens.hs view
@@ -102,6 +102,10 @@   , ( #~ ), ( #%~ ), ( #%%~ ), (<#~), (<#%~)   , ( #= ), ( #%= ), ( #%%= ), (<#=), (<#%=) +  -- * Common Lenses+  , devoid+  , united+   -- * Context   , Context(..)   , Context'@@ -119,6 +123,7 @@ import Data.Profunctor import Data.Profunctor.Rep import Data.Profunctor.Unsafe+import Data.Void  {-# ANN module "HLint: ignore Use ***" #-} @@ -916,6 +921,7 @@   State.put t   return r #endif+{-# INLINE ( #%%= ) #-}  -- | A version of ('Control.Lens.Setter.<.~') that works on 'ALens'. --@@ -923,9 +929,37 @@ -- ("world",("hello","world")) (<#~) :: ALens s t a b -> b -> s -> (b, t) l <#~ b = \s -> (b, storing l b s)+{-# INLINE (<#~) #-}  -- | A version of ('Control.Lens.Setter.<#=') that works on 'ALens'. (<#=) :: MonadState s m => ALens s s a b -> b -> m b l <#= b = do   l #= b   return b+{-# INLINE (<#=) #-}++-- | There is a field for every type in the 'Void'. Very zen.+--+-- >>> [] & mapped.devoid +~ 1+-- []+--+-- Nothing & mapped.devoid %~ abs+-- Nothing+--+-- @+-- 'devoid' :: 'Lens'' 'Void' a+-- @+devoid :: Over p f Void Void a b+devoid _ = absurd+{-# INLINE devoid #-}++-- | We can always retrieve a @()@ from any type.+--+-- >>> "hello"^.united+-- ()+--+-- >>> "hello" & united .~ ()+-- "hello"+united :: Lens' a ()+united f v = f () <&> \ () -> v+{-# INLINE united #-}
src/Control/Lens/Prism.hs view
@@ -31,6 +31,9 @@   , _Left   , _Right   , _Just+  , _Nothing+  , _Void+  , only   -- * Prismatic profunctors   , Choice(..)   ) where@@ -40,8 +43,10 @@ import Control.Lens.Internal.Prism import Control.Lens.Internal.Setter import Control.Lens.Type+import Control.Monad import Data.Bifunctor import Data.Profunctor+import Data.Void #ifndef SAFE import Unsafe.Coerce #endif@@ -99,9 +104,10 @@ prism bt seta = dimap seta (either pure (fmap bt)) . right' {-# INLINE prism #-} --- | Build a 'Prism''.-prism' :: (a -> s) -> (s -> Maybe a) -> Prism' s a-prism' as sma = prism as (\s -> maybe (Left s) Right (sma s))+-- | This is usually used to build a 'Prism'', when you have to use an operation like+-- 'Data.Typeable.cast' which already returns a 'Maybe'.+prism' :: (b -> s) -> (s -> Maybe a) -> Prism s s a b+prism' bs sma = prism bs (\s -> maybe (Left s) Right (sma s)) {-# INLINE prism' #-}  -- | Use a 'Prism' as a kind of first-class pattern.@@ -228,3 +234,36 @@ _Just :: Prism (Maybe a) (Maybe b) a b _Just = prism Just $ maybe (Left Nothing) Right {-# INLINE _Just #-}++-- | This 'Prism' provides the 'Traversal' of a 'Nothing' in a 'Maybe'.+--+-- >>> Nothing ^? _Nothing+-- Just ()+--+-- >>> Just () ^? _Nothing+-- Nothing+--+-- But you can turn it around and use it to construct 'Nothing' as well:+--+-- >>> _Nothing # ()+-- Nothing+_Nothing :: Prism' (Maybe a) ()+_Nothing = prism' (const Nothing) $ maybe (Just ()) (const Nothing)+{-# INLINE _Nothing #-}++-- | 'Void' is a logically uninhabited data type.+--+-- This is a 'Prism' that will always fail to match.+_Void :: Prism s s a Void+_Void = prism absurd Left+{-# INLINE _Void #-}++-- | This 'Prism' compares for exact equality with a given value.+--+-- >>> only 4 # ()+-- 4+--+-- >>> 5 ^? only 4+-- Nothing+only :: Eq a => a -> Prism' a ()+only a = prism' (\() -> a) $ guard . (a ==)
src/Control/Lens/Tuple.hs view
@@ -62,7 +62,7 @@   --   -- This can also be used on larger tuples as well:   ---  -- >>> _1 +~ 41 $ (1,2,3,4,5)+  -- >>> (1,2,3,4,5) & _1 +~ 41   -- (42,2,3,4,5)   --   -- @
src/Control/Lens/Type.hs view
@@ -307,15 +307,15 @@ -- -- There are two laws that a 'Prism' should satisfy: ----- First, if I 'Control.Lens.Review.re' or 'Control.Lens.Prism.review' a value with a 'Prism' and then 'Control.Lens.Prism.preview' or use ('Control.Lens.Fold.^?'), I will get it back:+-- First, if I 'Control.Lens.Review.re' or 'Control.Lens.Prism.review' a value with a 'Prism' and then 'Control.Lens.Fold.preview' or use ('Control.Lens.Fold.^?'), I will get it back: -- -- @--- 'Control.Lens.Prism.preview' l ('Control.Lens.Prism.review' l b) ≡ 'Just' b+-- 'Control.Lens.Fold.preview' l ('Control.Lens.Prism.review' l b) ≡ 'Just' b -- @ -- -- Second, if you can extract a value @a@ using a 'Prism' @l@ from a value @s@, then the value @s@ is completely described my @l@ and @a@: ----- If @'Control.Lens.Prism.preview' l s ≡ 'Just' a@ then @'Control.Lens.Prism.review' l a ≡ s@+-- If @'Control.Lens.Fold.preview' l s ≡ 'Just' a@ then @'Control.Lens.Prism.review' l a ≡ s@ -- -- These two laws imply that the 'Traversal' laws hold for every 'Prism' and that we 'Data.Traversable.traverse' at most 1 element: --
src/Data/ByteString/Lazy/Lens.hs view
@@ -34,8 +34,8 @@ -- 'Data.ByteString.unpack' x ≡ x '^.' 'from' 'packedBytes' -- @ ----- >>> [104,101,108,108,111]^.packedBytes--- Chunk "hello" Empty+-- >>> [104,101,108,108,111]^.packedBytes == Char8.pack "hello"+-- True packedBytes :: Iso' [Word8] ByteString packedBytes = iso Words.pack unpackLazy {-# INLINE packedBytes #-}
src/Data/List/Split/Lens.hs view
@@ -32,7 +32,6 @@   , keepFinalBlanks   ) where -import Control.Applicative import Control.Lens import Data.Monoid import Data.List.Split@@ -46,7 +45,7 @@ -- @ -- 'splitting' :: 'Splitter' a -> 'Fold' i s a -> 'Fold' [i] s [a] -- @-splitting :: (Applicative f, Gettable f) => Splitter a -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+splitting :: Splitter a -> Getting (Endo [a]) s s a a -> Fold s [a] splitting s l f = coerce . traverse f . split s . toListOf l {-# INLINE splitting #-} @@ -57,7 +56,7 @@ -- @ -- 'splittingOn' :: 'Eq' a => [a] -> 'Fold' s a -> 'Fold' s [a] -- @-splittingOn :: (Applicative f, Gettable f, Eq a) => [a] -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+splittingOn :: Eq a => [a] -> Getting (Endo [a]) s s a a -> Fold s [a] splittingOn s l f = coerce . traverse f . splitOn s . toListOf l {-# INLINE splittingOn #-} @@ -68,7 +67,7 @@ -- @ -- 'splittingOn' :: 'Eq' a => [a] -> 'Fold' s a -> 'Fold' s [a] -- @-splittingOneOf :: (Applicative f, Gettable f, Eq a) => [a] -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+splittingOneOf :: Eq a => [a] -> Getting (Endo [a]) s s a a -> Fold s [a] splittingOneOf s l f = coerce . traverse f . splitOneOf s . toListOf l {-# INLINE splittingOneOf #-} @@ -79,7 +78,7 @@ -- @ -- 'splittingOn' :: (a -> 'Bool') -> 'Fold' s a -> 'Fold' s [a] -- @-splittingWhen :: (Applicative f, Gettable f, Eq a) => (a -> Bool) -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+splittingWhen :: Eq a => (a -> Bool) -> Getting (Endo [a]) s s a a -> Fold s [a] splittingWhen s l f = coerce . traverse f . splitWhen s . toListOf l {-# INLINE splittingWhen #-} @@ -90,7 +89,7 @@ -- @ -- 'endingBy' :: 'Eq' a => [a] -> 'Fold' s a -> 'Fold' s [a] -- @-endingBy :: (Applicative f, Gettable f, Eq a) => [a] -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+endingBy :: Eq a => [a] -> Getting (Endo [a]) s s a a -> Fold s [a] endingBy s l f = coerce . traverse f . endBy s . toListOf l {-# INLINE endingBy #-} @@ -101,7 +100,7 @@ -- @ -- 'endingByOneOf' :: 'Eq' a => [a] -> 'Fold' s a -> 'Fold' s [a] -- @-endingByOneOf :: (Applicative f, Gettable f, Eq a) => [a] -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+endingByOneOf :: Eq a => [a] -> Getting (Endo [a]) s s a a -> Fold s [a] endingByOneOf s l f = coerce . traverse f . endByOneOf s . toListOf l {-# INLINE endingByOneOf #-} @@ -112,7 +111,7 @@ -- @ -- 'wordingBy' :: (a -> 'Bool') -> 'Fold' a -> 'Fold' s [a] -- @-wordingBy :: (Applicative f, Gettable f, Eq a) => (a -> Bool) -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+wordingBy :: Eq a => (a -> Bool) -> Getting (Endo [a]) s s a a -> Fold s [a] wordingBy s l f = coerce . traverse f . wordsBy s . toListOf l {-# INLINE wordingBy #-} @@ -123,7 +122,7 @@ -- @ -- 'liningBy' :: (a -> 'Bool') -> 'Fold' s a -> 'Fold' s [a] -- @-liningBy :: (Applicative f, Gettable f, Eq a) => (a -> Bool) -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+liningBy :: Eq a => (a -> Bool) -> Getting (Endo [a]) s s a a -> Fold s [a] liningBy s l f = coerce . traverse f . linesBy s . toListOf l {-# INLINE liningBy #-} @@ -132,8 +131,8 @@ -- @ -- 'chunkingOf' :: 'Int' -> 'Fold' s a -> 'Fold' s [a] -- @-chunking :: (Applicative f, Gettable f) => Int -- ^ @n@-            -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+chunking :: Int -- ^ @n@+            -> Getting (Endo [a]) s s a a -> Fold s [a] chunking s l f = coerce . traverse f . chunksOf s . toListOf l {-# INLINE chunking #-} @@ -142,7 +141,7 @@ -- @ -- 'splittingPlaces' :: 'Integral' n => [n] -> 'Fold' s a -> 'Fold' s [a] -- @-splittingPlaces :: (Applicative f, Gettable f, Integral n) => [n] -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+splittingPlaces :: Integral n => [n] -> Getting (Endo [a]) s s a a -> Fold s [a] splittingPlaces s l f = coerce . traverse f . splitPlaces s . toListOf l {-# INLINE splittingPlaces #-} @@ -151,7 +150,7 @@ -- @ -- 'splittingPlacesBlanks' :: 'Integral' n => [n] -> 'Fold' s a -> 'Fold' s [a] -- @-splittingPlacesBlanks :: (Applicative f, Gettable f, Integral n) => [n] -> Getting (Endo [a]) s s a a -> LensLike f s s [a] [a]+splittingPlacesBlanks :: Integral n => [n] -> Getting (Endo [a]) s s a a -> Fold s [a] splittingPlacesBlanks s l f = coerce . traverse f . splitPlacesBlanks s . toListOf l {-# INLINE splittingPlacesBlanks #-}