lens-family 1.0.1 → 1.1.0
raw patch · 8 files changed
+133/−35 lines, 8 filesdep ~lens-family-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: lens-family-core
API changes (from Hackage documentation)
- Lens.Family2: data Getting c a :: * -> * -> *
- Lens.Family2: data Setting a :: * -> *
- Lens.Family2: type Fold' a b = Fold a a b b
- Lens.Family2: type Getter' a b = Fold a a b b
- Lens.Family2: type Lens' a b = Lens a a b b
- Lens.Family2: type Setter a a' b b' = LensLike Setting a a' b b'
- Lens.Family2: type Setter' a b = Setter a a b b
- Lens.Family2: type Traversal' a b = Traversal a a b b
- Lens.Family2.State.Lazy: type Setter a a' b b' = LensLike Setting a a' b b'
- Lens.Family2.State.Lazy: type Setter' a b = Setter a a b b
- Lens.Family2.State.Strict: type Setter a a' b b' = LensLike Setting a a' b b'
- Lens.Family2.State.Strict: type Setter' a b = Setter a a b b
- Lens.Family2.Stock: type Lens' a b = Lens a a b b
- Lens.Family2.Stock: type Traversal' a b = Traversal a a b b
- Lens.Family2.Unchecked: data Setting a :: * -> *
- Lens.Family2.Unchecked: type Lens' a b = Lens a a b b
- Lens.Family2.Unchecked: type Setter a a' b b' = LensLike Setting a a' b b'
- Lens.Family2.Unchecked: type Setter' a b = Setter a a b b
- Lens.Family2.Unchecked: type Traversal' a b = Traversal a a b b
+ Lens.Family2: class Applicative f => Identical (f :: * -> *)
+ Lens.Family2: data Constant a b :: * -> * -> *
+ Lens.Family2.State.Lazy: (<~) :: MonadState a m => Setter a a b b' -> m b' -> m ()
+ Lens.Family2.State.Lazy: class Applicative f => Identical (f :: * -> *)
+ Lens.Family2.State.Lazy: data Constant a b :: * -> * -> *
+ Lens.Family2.State.Strict: (<~) :: MonadState a m => Setter a a b b' -> m b' -> m ()
+ Lens.Family2.State.Strict: class Applicative f => Identical (f :: * -> *)
+ Lens.Family2.State.Strict: data Constant a b :: * -> * -> *
+ Lens.Family2.Stock: class Applicative f => Identical (f :: * -> *)
+ Lens.Family2.Stock: mapped :: Functor f => Setter (f a) (f a') a a'
+ Lens.Family2.Unchecked: class Applicative f => Identical (f :: * -> *)
- Lens.Family2: type FoldLike r a a' b b' = LensLike (Getting r) a a' b b'
+ Lens.Family2: type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'
- Lens.Family2: type FoldLike' r a b = LensLike (Getting r) a a b b
+ Lens.Family2: type FoldLike' r a b = LensLike' (Constant r) a b
- Lens.Family2.State.Lazy: type FoldLike r a a' b b' = LensLike (Getting r) a a' b b'
+ Lens.Family2.State.Lazy: type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'
- Lens.Family2.State.Lazy: type LensLike (f :: * -> *) a a' b b' = (b -> f b') -> a -> f a'
+ Lens.Family2.State.Lazy: type Setter a a' b b' = forall f. Identical f => LensLike f a a' b b'
- Lens.Family2.State.Lazy: type LensLike' (f :: * -> *) a b = (b -> f b) -> a -> f a
+ Lens.Family2.State.Lazy: type Setter' a b = forall f. Identical f => LensLike' f a b
- Lens.Family2.State.Strict: type FoldLike r a a' b b' = LensLike (Getting r) a a' b b'
+ Lens.Family2.State.Strict: type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'
- Lens.Family2.State.Strict: type LensLike (f :: * -> *) a a' b b' = (b -> f b') -> a -> f a'
+ Lens.Family2.State.Strict: type Setter a a' b b' = forall f. Identical f => LensLike f a a' b b'
- Lens.Family2.State.Strict: type LensLike' (f :: * -> *) a b = (b -> f b) -> a -> f a
+ Lens.Family2.State.Strict: type Setter' a b = forall f. Identical f => LensLike' f a b
Files
- CHANGELOG +8/−0
- LICENSE +1/−1
- lens-family.cabal +3/−3
- src/Lens/Family2.hs +60/−11
- src/Lens/Family2/State/Lazy.hs +12/−5
- src/Lens/Family2/State/Strict.hs +12/−5
- src/Lens/Family2/Stock.hs +14/−5
- src/Lens/Family2/Unchecked.hs +23/−5
CHANGELOG view
@@ -1,3 +1,11 @@+1.1.0 (Changes from 1.0.1)+=========================+* Some type synonym definitions have been altered, but should be equivalent.+* Removed Getting and Setting functors and instead use the equivalent standard functors Const and Identity.+* Renamed Setter to ASetter and generalized Setters to be a LensLike constrained to an "Identical" functor.+* Added the (<~) operator.+* Corrected the definition of ATraversal'+ 1.0.1 (Changes from 1.0.0) ========================= * Bump dependency on transformers and mtl
LICENSE view
@@ -1,4 +1,4 @@-Copyright 2012 Russell O'Connor+Copyright 2012,2013,2014 Russell O'Connor All rights reserved.
lens-family.cabal view
@@ -1,13 +1,13 @@ name: lens-family category: Data, Lenses-version: 1.0.1+version: 1.1.0 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE author: Russell O'Connor maintainer: Russell O'Connor <roconnor@theorem.ca> stability: experimental-copyright: Copyright (C) 2012,2013 Russell O'Connor+copyright: Copyright (C) 2012,2013,2014 Russell O'Connor synopsis: Lens Families description: Lens Families build-type: Simple@@ -36,7 +36,7 @@ containers >= 0.3 && < 0.6, transformers >= 0.2.0 && < 0.5, mtl >= 2.1 && < 2.3,- lens-family-core >= 1.0 && < 1.1+ lens-family-core >= 1.1 && < 1.2 exposed-modules: Lens.Family2.Unchecked
src/Lens/Family2.hs view
@@ -49,12 +49,12 @@ -- The result will be a 'Data.Monid.mconcat' of all the fields referenced. -- The various @fooOf@ functions can be used to access different monoidal summaries of some kinds of values. ----- '^?' can be used to access the first value of a traverasal.+-- '^?' can be used to access the first value of a traversal. -- 'Nothing' is returned when the traversal has no references. -- -- '^..' can be used with a traversals and will return a list of all fields referenced. ----- When 'LF..~' is used with a traveral, all referenced fields will be set to the same value, and when 'LF.%~' is used with a traversal, all referenced fields will be modified with the same function.+-- When 'LF..~' is used with a traversal, all referenced fields will be set to the same value, and when 'LF.%~' is used with a traversal, all referenced fields will be modified with the same function. -- -- Like lenses, traversals can be composed with '.', and because every lens is automatically a traversal, lenses and traversals can be composed with '.' yielding a traversal. --@@ -81,20 +81,21 @@ , toListOf, allOf, anyOf, firstOf, lastOf, sumOf, productOf , lengthOf, nullOf , LF.backwards- , LF.over, (LF.%~), LF.set, (LF..~)+ , over, (%~), set, (.~) , (LF.&)- -- * Pseudo-imperatives- , (LF.+~), (LF.*~), (LF.-~), (LF.//~), (LF.&&~), (LF.||~), (LF.<>~)- -- * Types+-- * Pseudo-imperatives+ , (+~), (*~), (-~), (//~), (&&~), (||~), (<>~)+-- * Types , Lens, Lens' , Traversal, Traversal'+ , Setter, Setter' , Getter, Getter' , Fold, Fold'- , LF.Setter, LF.Setter' , LF.LensLike, LF.LensLike' , LF.FoldLike, LF.FoldLike'- , LF.Getting, LF.Setting+ , LF.Constant , LF.Phantom+ , Identical -- * Re-exports , Applicative, Foldable, Monoid , LF.Backwards@@ -104,13 +105,16 @@ import Data.Foldable (Foldable) import Data.Monoid (Monoid) import qualified Lens.Family as LF-import Lens.Family2.Unchecked (Lens, Lens', Traversal, Traversal')+import Lens.Family2.Unchecked ( Lens, Lens'+ , Traversal, Traversal'+ , Setter, Setter', Identical+ ) type Fold a a' b b' = forall f. (LF.Phantom f, Applicative f) => LF.LensLike f a a' b b'-type Fold' a b = Fold a a b b+type Fold' a b = forall f. (LF.Phantom f, Applicative f) => LF.LensLike' f a b type Getter a a' b b' = forall f. LF.Phantom f => LF.LensLike f a a' b b'-type Getter' a b = Fold a a b b+type Getter' a b = forall f. LF.Phantom f=> LF.LensLike' f a b -- |'to' promotes a projection function to a read-only lens called a getter. -- To demote a lens to a projection function, use the section @(^.l)@ or @view l@.@@ -134,6 +138,7 @@ allOf :: Fold a a' b b' -> (b -> Bool) -> a -> Bool allOf l = LF.allOf l +-- | Returns true if any of the referenced values satisfy the given predicate. anyOf :: Fold a a' b b' -> (b -> Bool) -> a -> Bool anyOf l = LF.anyOf l @@ -176,3 +181,47 @@ -- Returns 'Nothing' if there are no referenced values. (^?) :: a -> Fold a a' b b' -> Maybe b x^?l = x LF.^? l++-- | Demote a setter to a semantic editor combinator.+over :: Setter a a' b b' -> (b -> b') -> a -> a'+over l = LF.over l++infixr 4 %~++-- | Modify all referenced fields.+(%~) :: Setter a a' b b' -> (b -> b') -> a -> a'+l %~ f = l LF.%~ f++infixr 4 .~++-- | Set all referenced fields to the given value.+(.~) :: Setter a a' b b' -> b' -> a -> a'+l .~ b = l LF..~ b++-- | Set all referenced fields to the given value.+set :: Setter a a' b b' -> b' -> a -> a'+set l = LF.set l++infixr 4 +~, -~, *~++(+~), (-~), (*~) :: Num b => Setter' a b -> b -> a -> a+f +~ b = f LF.+~ b+f -~ b = f LF.-~ b+f *~ b = f LF.*~ b++infixr 4 //~++(//~) :: Fractional b => Setter' a b -> b -> a -> a+f //~ b = f LF.//~ b++infixr 4 &&~, ||~++(&&~), (||~) :: Setter' a Bool -> Bool -> a -> a+f &&~ b = f LF.&&~ b+f ||~ b = f LF.||~ b++infixr 4 <>~++-- | Monoidally append a value to all referenced fields.+(<>~) :: (Monoid o) => Setter' a o -> o -> a -> a+f <>~ o = f LF.<>~ o
src/Lens/Family2/State/Lazy.hs view
@@ -8,6 +8,7 @@ , (%=) , assign, (.=) , (%%=)+ , (<~) -- * Compound Assignments , (+=), (-=), (*=) , (//=)@@ -17,8 +18,8 @@ , LFS.Zooming -- * Re-exports , LensLike, LensLike'- , FoldLike- , Setter, Setter'+ , FoldLike, Constant+ , Setter, Setter', Identical , LFS.StateT, MonadState, Writer , Monoid ) where@@ -29,8 +30,8 @@ import Control.Monad.Trans.Writer.Lazy (Writer, writer, runWriter) import Control.Monad.State.Lazy (MonadState, get, modify, state) import Lens.Family2 ( LensLike, LensLike'- , FoldLike- , Setter, Setter'+ , FoldLike, Constant+ , Setter, Setter', Identical , view, views, (%~) ) import qualified Lens.Family.State.Lazy as LFS@@ -62,7 +63,7 @@ -- -- Retrieve a field of the state and pass it through the function @f :: b -> r@. ----- @uses l f = f <$> use l@+-- @uses l f = f \<$> use l@ uses l f = views l f `liftM` get infix 4 %=@@ -80,6 +81,12 @@ -- | Set a field of the state. assign :: MonadState a m => Setter a a b b' -> b' -> m () assign = (.=)++infixr 2 <~++-- | Set a field of the state using the result of executing a stateful command.+(<~) :: MonadState a m => Setter a a b b' -> m b' -> m ()+l <~ v = assign l =<< v infix 4 %%=
src/Lens/Family2/State/Strict.hs view
@@ -8,6 +8,7 @@ , (%=) , assign, (.=) , (%%=)+ , (<~) -- * Compound Assignments , (+=), (-=), (*=) , (//=)@@ -17,8 +18,8 @@ , LFS.Zooming -- * Re-exports , LensLike, LensLike'- , FoldLike- , Setter, Setter'+ , FoldLike, Constant+ , Setter, Setter', Identical , LFS.StateT, MonadState, Writer , Monoid ) where@@ -29,8 +30,8 @@ import Control.Monad.Trans.Writer.Lazy (Writer, writer, runWriter) import Control.Monad.State.Strict (MonadState, get, modify, state) import Lens.Family2 ( LensLike, LensLike'- , FoldLike- , Setter, Setter'+ , FoldLike, Constant+ , Setter, Setter', Identical , view, views, (%~) ) import qualified Lens.Family.State.Strict as LFS@@ -62,7 +63,7 @@ -- -- Retrieve a field of the state and pass it through the function @f :: b -> r@. ----- @uses l f = f <$> use l@+-- @uses l f = f \<$> use l@ uses l f = views l f `liftM` get infix 4 %=@@ -80,6 +81,12 @@ -- | Set a field of the state. assign :: MonadState a m => Setter a a b b' -> b' -> m () assign = (.=)++infixr 2 <~++-- | Set a field of the state using the result of executing a stateful command.+(<~) :: MonadState a m => Setter a a b b' -> m b' -> m ()+l <~ v = assign l =<< v infix 4 %%=
src/Lens/Family2/Stock.hs view
@@ -7,27 +7,32 @@ , Stock.alongside , Stock.beside -- * Stock Lenses- , _1, _2, both+ , _1, _2 , chosen , ix , at, intAt , contains, intContains -- * Stock Traversals+ , both , _Left, _Right , _Just, _Nothing , ignored+-- * Stock SECs+ , mapped -- * Types , Stock.AlongsideLeft, Stock.AlongsideRight -- * Re-exports , Lens, Lens' , Traversal, Traversal'+ , Setter , Stock.LensLike, Stock.LensLike'- , Stock.Applicative+ , Stock.Applicative, Stock.Identical ) where import qualified Lens.Family.Stock as Stock import Lens.Family2 ( Lens, Lens' , Traversal, Traversal'+ , Setter ) import qualified Data.Map as Map import qualified Data.IntMap as IntMap@@ -47,11 +52,11 @@ chosen = Stock.chosen -- | Lens on a given point of a function.-ix :: (Eq k) => k -> Lens' (k -> v) v+ix :: Eq k => k -> Lens' (k -> v) v ix = Stock.ix -- | Lens on a given point of a 'Map.Map'.-at :: (Ord k) => k -> Lens' (Map.Map k v) (Maybe v)+at :: Ord k => k -> Lens' (Map.Map k v) (Maybe v) at = Stock.at -- | Lens on a given point of a 'IntMap.IntMap'.@@ -59,7 +64,7 @@ intAt = Stock.intAt -- | Lens on a given point of a 'Set.Set'.-contains :: (Ord k) => k -> Lens' (Set.Set k) Bool+contains :: Ord k => k -> Lens' (Set.Set k) Bool contains = Stock.contains -- | Lens on a given point of a 'IntSet.IntSet'.@@ -89,3 +94,7 @@ -- | The empty traveral on any type. ignored :: Traversal a a b b' ignored = Stock.ignored++-- | An SEC referencing the parameter of a functor.+mapped :: Functor f => Setter (f a) (f a') a a'+mapped = Stock.mapped
src/Lens/Family2/Unchecked.hs view
@@ -77,13 +77,13 @@ -- * Documentation lens , iso- , LF.setting+ , setting -- * Types , Lens, Lens' , Traversal, Traversal'- , LF.Setting+ , Setter, Setter' , LF.LensLike, LF.LensLike'- , LF.Setter, LF.Setter'+ , LF.Identical -- * Re-exports , Applicative ) where@@ -92,11 +92,14 @@ import qualified Lens.Family.Unchecked as LF type Lens a a' b b' = forall f. Functor f => LF.LensLike f a a' b b'-type Lens' a b = Lens a a b b+type Lens' a b = forall f. Functor f => LF.LensLike' f a b type Traversal a a' b b' = forall f. Applicative f => LF.LensLike f a a' b b'-type Traversal' a b = Traversal a a b b+type Traversal' a b = forall f. Applicative f => LF.LensLike' f a b +type Setter a a' b b' = forall f. LF.Identical f => LF.LensLike f a a' b b'+type Setter' a b = forall f. LF.Identical f => LF.LensLike' f a b+ -- | Build a lens from a @getter@ and @setter@ families. -- -- /Caution/: In order for the generated lens family to be well-defined, you must ensure that the three lens laws hold:@@ -122,3 +125,18 @@ -> (b' -> a') -- ^ yang -> Lens a a' b b' iso = LF.iso++-- | 'setting' promotes a \"semantic editor combinator\" to a modify-only lens.+-- To demote a lens to a semantic edit combinator, use the section @(l %~)@ or @over l@ from "Lens.Family2".+--+-- >>> setting map . fstL %~ length $ [("The",0),("quick",1),("brown",1),("fox",2)]+-- [(3,0),(5,1),(5,1),(3,2)]+--+-- /Caution/: In order for the generated setter family to be well-defined, you must ensure that the two functors laws hold:+-- +-- * @sec id === id@+--+-- * @sec f . sec g === sec (f . g)@+setting :: ((b -> b') -> a -> a') -- ^ sec (semantic editor combinator)+ -> Setter a a' b b'+setting = LF.setting