lens-family-core 1.0.1 → 1.1.0
raw patch · 11 files changed
+136/−99 lines, 11 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Lens.Family: data Getting c a
- Lens.Family: data Setting a
- Lens.Family: instance Functor (Getting c)
- Lens.Family: instance Monoid c => Applicative (Getting c)
- Lens.Family: instance Phantom (Getting c)
- Lens.Family: type Setter a a' b b' = LensLike Setting a a' b b'
- Lens.Family: type Setter' a b = Setter a a b b
- Lens.Family.State.Lazy: type Setter a a' b b' = LensLike Setting a a' b b'
- Lens.Family.State.Lazy: type Setter' a b = Setter a a b b
- Lens.Family.State.Strict: type Setter a a' b b' = LensLike Setting a a' b b'
- Lens.Family.State.Strict: type Setter' a b = Setter a a b b
- Lens.Family.Unchecked: data Setting a
- Lens.Family.Unchecked: type Setter a a' b b' = LensLike Setting a a' b b'
- Lens.Family.Unchecked: type Setter' a b = Setter a a b b
+ Lens.Family: data Constant a b :: * -> * -> *
+ Lens.Family: data Identity a :: * -> *
+ Lens.Family: type ASetter a a' b b' = LensLike Identity a a' b b'
+ Lens.Family: type ASetter' a b = LensLike' Identity a b
+ Lens.Family.Clone: class Applicative f => Identical f
+ Lens.Family.Clone: cloneSetter :: Identical f => ASetter a a' b b' -> LensLike f a a' b b'
+ Lens.Family.Clone: type ASetter a a' b b' = LensLike Identity a a' b b'
+ Lens.Family.Clone: type FoldLike' r a b = LensLike' (Constant r) a b
+ Lens.Family.Clone: type LensLike' f a b = (b -> f b) -> (a -> f a)
+ Lens.Family.State.Lazy: (<~) :: Monad m => ASetter a a b b' -> StateT a m b' -> StateT a m ()
+ Lens.Family.State.Lazy: data Constant a b :: * -> * -> *
+ Lens.Family.State.Lazy: data Identity a :: * -> *
+ Lens.Family.State.Lazy: type ASetter a a' b b' = LensLike Identity a a' b b'
+ Lens.Family.State.Lazy: type ASetter' a b = LensLike' Identity a b
+ Lens.Family.State.Strict: (<~) :: Monad m => ASetter a a b b' -> StateT a m b' -> StateT a m ()
+ Lens.Family.State.Strict: data Constant a b :: * -> * -> *
+ Lens.Family.State.Strict: data Identity a :: * -> *
+ Lens.Family.State.Strict: type ASetter a a' b b' = LensLike Identity a a' b b'
+ Lens.Family.State.Strict: type ASetter' a b = LensLike' Identity a b
+ Lens.Family.Stock: class Applicative f => Identical f
+ Lens.Family.Stock: mapped :: (Identical f, Functor g) => LensLike f (g a) (g a') a a'
+ Lens.Family.Unchecked: class Applicative f => Identical f
- Lens.Family: (%~) :: Setter a a' b b' -> (b -> b') -> a -> a'
+ Lens.Family: (%~) :: ASetter a a' b b' -> (b -> b') -> a -> a'
- Lens.Family: (&&~) :: Setter' a Bool -> Bool -> a -> a
+ Lens.Family: (&&~) :: ASetter' a Bool -> Bool -> a -> a
- Lens.Family: (*~) :: Num b => Setter' a b -> b -> a -> a
+ Lens.Family: (*~) :: Num b => ASetter' a b -> b -> a -> a
- Lens.Family: (+~) :: Num b => Setter' a b -> b -> a -> a
+ Lens.Family: (+~) :: Num b => ASetter' a b -> b -> a -> a
- Lens.Family: (-~) :: Num b => Setter' a b -> b -> a -> a
+ Lens.Family: (-~) :: Num b => ASetter' a b -> b -> a -> a
- Lens.Family: (.~) :: Setter a a' b b' -> b' -> a -> a'
+ Lens.Family: (.~) :: ASetter a a' b b' -> b' -> a -> a'
- Lens.Family: (//~) :: Fractional b => Setter' a b -> b -> a -> a
+ Lens.Family: (//~) :: Fractional b => ASetter' a b -> b -> a -> a
- Lens.Family: (<>~) :: Monoid o => Setter' a o -> o -> a -> a
+ Lens.Family: (<>~) :: Monoid o => ASetter' a o -> o -> a -> a
- Lens.Family: (||~) :: Setter' a Bool -> Bool -> a -> a
+ Lens.Family: (||~) :: ASetter' a Bool -> Bool -> a -> a
- Lens.Family: over :: Setter a a' b b' -> (b -> b') -> a -> a'
+ Lens.Family: over :: ASetter a a' b b' -> (b -> b') -> a -> a'
- Lens.Family: set :: Setter a a' b b' -> b' -> a -> a'
+ Lens.Family: set :: ASetter a a' b b' -> b' -> a -> a'
- Lens.Family: type FoldLike r a a' b b' = LensLike (Getting r) a a' b b'
+ Lens.Family: type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'
- Lens.Family: type FoldLike' r a b = LensLike (Getting r) a a b b
+ Lens.Family: type FoldLike' r a b = LensLike' (Constant r) a b
- Lens.Family.Clone: type AFold' a b = AFold a a b b
+ Lens.Family.Clone: type AFold' a b = FoldLike' [b] a b
- Lens.Family.Clone: type AGetter' a b = AGetter a a b b
+ Lens.Family.Clone: type AGetter' a b = FoldLike' b a b
- Lens.Family.Clone: type ALens' a b = ALens a a b b
+ Lens.Family.Clone: type ALens' a b = LensLike' (IStore b b) a b
- Lens.Family.Clone: type ATraversal' a b = ALens a a b b
+ Lens.Family.Clone: type ATraversal' a b = LensLike' (IKleeneStore b b) a b
- Lens.Family.Clone: type FoldLike r a a' b b' = LensLike (Getting r) a a' b b'
+ Lens.Family.Clone: type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'
- Lens.Family.State.Lazy: (%=) :: Monad m => Setter a a b b' -> (b -> b') -> StateT a m ()
+ Lens.Family.State.Lazy: (%=) :: Monad m => ASetter a a b b' -> (b -> b') -> StateT a m ()
- Lens.Family.State.Lazy: (&&=) :: Monad m => Setter' a Bool -> Bool -> StateT a m ()
+ Lens.Family.State.Lazy: (&&=) :: Monad m => ASetter' a Bool -> Bool -> StateT a m ()
- Lens.Family.State.Lazy: (*=) :: (Monad m, Num b) => Setter' a b -> b -> StateT a m ()
+ Lens.Family.State.Lazy: (*=) :: (Monad m, Num b) => ASetter' a b -> b -> StateT a m ()
- Lens.Family.State.Lazy: (+=) :: (Monad m, Num b) => Setter' a b -> b -> StateT a m ()
+ Lens.Family.State.Lazy: (+=) :: (Monad m, Num b) => ASetter' a b -> b -> StateT a m ()
- Lens.Family.State.Lazy: (-=) :: (Monad m, Num b) => Setter' a b -> b -> StateT a m ()
+ Lens.Family.State.Lazy: (-=) :: (Monad m, Num b) => ASetter' a b -> b -> StateT a m ()
- Lens.Family.State.Lazy: (.=) :: Monad m => Setter a a b b' -> b' -> StateT a m ()
+ Lens.Family.State.Lazy: (.=) :: Monad m => ASetter a a b b' -> b' -> StateT a m ()
- Lens.Family.State.Lazy: (//=) :: (Monad m, Fractional b) => Setter' a b -> b -> StateT a m ()
+ Lens.Family.State.Lazy: (//=) :: (Monad m, Fractional b) => ASetter' a b -> b -> StateT a m ()
- Lens.Family.State.Lazy: (<>=) :: (Monoid o, Monad m) => Setter' a o -> o -> StateT a m ()
+ Lens.Family.State.Lazy: (<>=) :: (Monoid o, Monad m) => ASetter' a o -> o -> StateT a m ()
- Lens.Family.State.Lazy: (||=) :: Monad m => Setter' a Bool -> Bool -> StateT a m ()
+ Lens.Family.State.Lazy: (||=) :: Monad m => ASetter' a Bool -> Bool -> StateT a m ()
- Lens.Family.State.Lazy: assign :: Monad m => Setter a a b b' -> b' -> StateT a m ()
+ Lens.Family.State.Lazy: assign :: Monad m => ASetter a a b b' -> b' -> StateT a m ()
- Lens.Family.State.Lazy: type FoldLike r a a' b b' = LensLike (Getting r) a a' b b'
+ Lens.Family.State.Lazy: type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'
- Lens.Family.State.Strict: (%=) :: Monad m => Setter a a b b' -> (b -> b') -> StateT a m ()
+ Lens.Family.State.Strict: (%=) :: Monad m => ASetter a a b b' -> (b -> b') -> StateT a m ()
- Lens.Family.State.Strict: (&&=) :: Monad m => Setter' a Bool -> Bool -> StateT a m ()
+ Lens.Family.State.Strict: (&&=) :: Monad m => ASetter' a Bool -> Bool -> StateT a m ()
- Lens.Family.State.Strict: (*=) :: (Monad m, Num b) => Setter' a b -> b -> StateT a m ()
+ Lens.Family.State.Strict: (*=) :: (Monad m, Num b) => ASetter' a b -> b -> StateT a m ()
- Lens.Family.State.Strict: (+=) :: (Monad m, Num b) => Setter' a b -> b -> StateT a m ()
+ Lens.Family.State.Strict: (+=) :: (Monad m, Num b) => ASetter' a b -> b -> StateT a m ()
- Lens.Family.State.Strict: (-=) :: (Monad m, Num b) => Setter' a b -> b -> StateT a m ()
+ Lens.Family.State.Strict: (-=) :: (Monad m, Num b) => ASetter' a b -> b -> StateT a m ()
- Lens.Family.State.Strict: (.=) :: Monad m => Setter a a b b' -> b' -> StateT a m ()
+ Lens.Family.State.Strict: (.=) :: Monad m => ASetter a a b b' -> b' -> StateT a m ()
- Lens.Family.State.Strict: (//=) :: (Monad m, Fractional b) => Setter' a b -> b -> StateT a m ()
+ Lens.Family.State.Strict: (//=) :: (Monad m, Fractional b) => ASetter' a b -> b -> StateT a m ()
- Lens.Family.State.Strict: (<>=) :: (Monoid o, Monad m) => Setter' a o -> o -> StateT a m ()
+ Lens.Family.State.Strict: (<>=) :: (Monoid o, Monad m) => ASetter' a o -> o -> StateT a m ()
- Lens.Family.State.Strict: (||=) :: Monad m => Setter' a Bool -> Bool -> StateT a m ()
+ Lens.Family.State.Strict: (||=) :: Monad m => ASetter' a Bool -> Bool -> StateT a m ()
- Lens.Family.State.Strict: assign :: Monad m => Setter a a b b' -> b' -> StateT a m ()
+ Lens.Family.State.Strict: assign :: Monad m => ASetter a a b b' -> b' -> StateT a m ()
- Lens.Family.State.Strict: type FoldLike r a a' b b' = LensLike (Getting r) a a' b b'
+ Lens.Family.State.Strict: type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'
- Lens.Family.Unchecked: setting :: ((b -> b') -> a -> a') -> Setter a a' b b'
+ Lens.Family.Unchecked: setting :: Identical f => ((b -> b') -> a -> a') -> LensLike f a a' b b'
Files
- CHANGELOG +8/−0
- LICENSE +1/−1
- lens-family-core.cabal +3/−3
- src/Lens/Family.hs +27/−35
- src/Lens/Family/Clone.hs +18/−11
- src/Lens/Family/Identical.hs +19/−0
- src/Lens/Family/Setting.hs +0/−12
- src/Lens/Family/State/Lazy.hs +19/−12
- src/Lens/Family/State/Strict.hs +19/−12
- src/Lens/Family/Stock.hs +14/−3
- src/Lens/Family/Unchecked.hs +8/−10
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
LICENSE view
@@ -1,4 +1,4 @@-Copyright 2012 Russell O'Connor+Copyright 2012,2013,2014 Russell O'Connor All rights reserved.
lens-family-core.cabal view
@@ -1,13 +1,13 @@ name: lens-family-core 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: Haskell 98 Lens Families description: Haskell 98 Lens Families build-type: Simple@@ -47,9 +47,9 @@ Lens.Family.State.Strict Lens.Family.State other-modules:+ Lens.Family.Identical Lens.Family.Phantom Lens.Family.State.Zoom- Lens.Family.Setting ghc-options: -Wall
src/Lens/Family.hs view
@@ -48,12 +48,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 '.~' is used with a traveral, all referenced fields will be set to the same value, and when '%~' is used with a traversal, all referenced fields will be modified with the same function.+-- When '.~' is used with a traversal, all referenced fields will be set to the same value, and when '%~' 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. --@@ -85,42 +85,33 @@ -- * Pseudo-imperatives , (+~), (*~), (-~), (//~), (&&~), (||~), (<>~) -- * Types- , Setter, Setter' , LensLike, LensLike' , FoldLike, FoldLike'- , Getting, Setting+ , ASetter, ASetter' , Phantom+ , Constant, Identity -- * Re-exports , Applicative, Foldable, Monoid , Backwards, All, Any, First, Last, Sum, Product ) where -import Control.Applicative (Applicative, pure, (<*>))+import Control.Applicative (Applicative) import Control.Applicative.Backwards (Backwards(..)) import Data.Foldable (Foldable, traverse_)-import Data.Monoid ( Monoid, mempty, mappend+import Data.Functor.Identity (Identity(..))+import Data.Functor.Constant (Constant(..))+import Data.Monoid ( Monoid, mappend , All(..), Any(..) , First(..), Last(..) , Sum(..), Product(..) ) import Lens.Family.Phantom (Phantom, coerce)-import Lens.Family.Setting (Setting(..))-import Lens.Family.Unchecked ( LensLike, LensLike'- , Setter, Setter')--newtype Getting c a = Getting { unGetting :: c }-instance Functor (Getting c) where- fmap _ (Getting c) = Getting c--instance Phantom (Getting c) where- coerce (Getting c) = Getting c--instance Monoid c => Applicative (Getting c) where- pure _ = Getting mempty- Getting a <*> Getting b = Getting (a `mappend` b)+import Lens.Family.Unchecked ( LensLike, LensLike' ) -type FoldLike r a a' b b' = LensLike (Getting r) a a' b b'-type FoldLike' r a b = LensLike (Getting r) a a b b+type FoldLike r a a' b b' = LensLike (Constant r) a a' b b'+type FoldLike' r a b = LensLike' (Constant r) a b+type ASetter a a' b b' = LensLike Identity a a' b b'+type ASetter' a b = LensLike' Identity a b to :: Phantom f => (a -> b) -> LensLike f a a' b b' -- ^ @@@ -174,7 +165,7 @@ -- @ -- views l f a = f (view l a) -- @-views l f = unGetting . l (Getting . f)+views l f = getConstant . l (Constant . f) toListOf :: FoldLike [b] a a' b b' -> a -> [b] -- ^ @@@ -249,7 +240,7 @@ -- @ -- -- Returns true if the number of references in the input is zero.-nullOf l = getAll . views l (const (All False))+nullOf l = allOf l (const False) infixr 8 ^. @@ -265,7 +256,7 @@ -- @ -- -- Access the monoidal summary referenced by a getter or lens.-x^.l = unGetting $ l Getting x+x^.l = getConstant $ l Constant x infixr 8 ^.. @@ -299,29 +290,30 @@ -- @ -- backwards :: Lens a a' b b' -> Lens a a' b b' -- backwards :: Getter a a' b b' -> Getter a a' b b'+-- backwards :: Setter a a' b b' -> Setter a a' b b' -- @ ----- No effect on lenses or getters.+-- No effect on lenses, getters or setters. backwards l f = forwards . l (Backwards . f) -- | Demote a setter to a semantic editor combinator.-over :: Setter a a' b b' -> (b -> b') -> a -> a'+over :: ASetter a a' b b' -> (b -> b') -> a -> a' over l = (l %~) infixr 4 %~ -- | Modify all referenced fields.-(%~) :: Setter a a' b b' -> (b -> b') -> a -> a'-l %~ f = unSetting . l (Setting . f)+(%~) :: ASetter a a' b b' -> (b -> b') -> a -> a'+l %~ f = runIdentity . l (Identity . f) infixr 4 .~ -- | Set all referenced fields to the given value.-(.~) :: Setter a a' b b' -> b' -> a -> a'+(.~) :: ASetter a a' b b' -> b' -> a -> a' l .~ b = l %~ const b -- | Set all referenced fields to the given value.-set :: Setter a a' b b' -> b' -> a -> a'+set :: ASetter a a' b b' -> b' -> a -> a' set = (.~) infixl 1 &@@ -332,24 +324,24 @@ infixr 4 +~, -~, *~ -(+~), (-~), (*~) :: Num b => Setter' a b -> b -> a -> a+(+~), (-~), (*~) :: Num b => ASetter' a b -> b -> a -> a f +~ b = f %~ (+ b) f -~ b = f %~ subtract b f *~ b = f %~ (* b) infixr 4 //~ -(//~) :: Fractional b => Setter' a b -> b -> a -> a+(//~) :: Fractional b => ASetter' a b -> b -> a -> a f //~ b = f %~ (/ b) infixr 4 &&~, ||~ -(&&~), (||~) :: Setter' a Bool -> Bool -> a -> a+(&&~), (||~) :: ASetter' a Bool -> Bool -> a -> a f &&~ b = f %~ (&& b) f ||~ b = f %~ (|| b) infixr 4 <>~ -- | Monoidally append a value to all referenced fields.-(<>~) :: (Monoid o) => Setter' a o -> o -> a -> a+(<>~) :: (Monoid o) => ASetter' a o -> o -> a -> a f <>~ o = f %~ (`mappend` o)
src/Lens/Family/Clone.hs view
@@ -5,6 +5,8 @@ -- -- * @Traversal@, @Traversal'@ --+-- * @Setter@, @Setter'@+-- -- * @Fold@, @Fold'@ -- -- * @Getter@, @Getter'@@@ -24,12 +26,11 @@ -- -- /Note/: It is important to eta-expand the definition of 'cl' to avoid the dreaded monomorphism restriction. ----- 'cloneTraversal', 'cloneGetter', and 'cloneFold' provides similar functionality for traversals, getters and folds respectively.--- Setters are already monomorphic, so do not need to be cloned.+-- 'cloneTraversal', 'cloneGetter', 'cloneSetter', and 'cloneFold' provides similar functionality for traversals, getters, setters, and folds respectively. -- -- /Note/: Cloning is only need if you use a functional reference multiple times with different instances. module Lens.Family.Clone- ( cloneLens, cloneTraversal, cloneGetter, cloneFold+ ( cloneLens, cloneTraversal, cloneSetter, cloneGetter, cloneFold -- * Types , ALens, ALens' , ATraversal, ATraversal'@@ -37,13 +38,15 @@ , AFold, AFold' , IStore, IKleeneStore -- * Re-exports- , LensLike, FoldLike- , Applicative, Phantom+ , LensLike, LensLike', FoldLike, FoldLike', ASetter+ , Applicative, Phantom, Identical ) where import Control.Applicative (Applicative, pure, (<*>), (<$>))-import Lens.Family ( LensLike- , FoldLike, toListOf, folding+import Lens.Family.Unchecked (Identical, setting)+import Lens.Family ( LensLike, LensLike'+ , ASetter, over+ , FoldLike, FoldLike', toListOf, folding , to, view , Phantom )@@ -56,7 +59,7 @@ type ALens a a' b b' = LensLike (IStore b b') a a' b b' -- | ALens' a b is a universal Lens' a b instance-type ALens' a b = ALens a a b b+type ALens' a b = LensLike' (IStore b b) a b -- | Converts a universal lens instance back into a polymorphic lens. cloneLens :: Functor f => ALens a a' b b' -> LensLike f a a' b b'@@ -81,7 +84,7 @@ type ATraversal a a' b b' = LensLike (IKleeneStore b b') a a' b b' -- | ATraversal' a b is a universal Traversal' a b instance-type ATraversal' a b = ALens a a b b+type ATraversal' a b = LensLike' (IKleeneStore b b) a b -- | Converts a universal traversal instance back into a polymorphic traversal. cloneTraversal :: Applicative f => ATraversal a a' b b' -> LensLike f a a' b b'@@ -91,11 +94,15 @@ research _ (Unit a) = pure a research f (Battery g b) = research f g <*> f b +-- | Converts a universal setter instance back into a polymorphic setter.+cloneSetter :: Identical f => ASetter a a' b b' -> LensLike f a a' b b'+cloneSetter = setting . over+ -- | AFold a a' b b' is a universal Fold' a a' b b' instance type AFold a a' b b' = FoldLike [b] a a' b b' -- | AFold' a b is a universal Fold' a b instance-type AFold' a b = AFold a a b b+type AFold' a b = FoldLike' [b] a b -- | Converts a universal fold instance back into a polymorphic fold. cloneFold :: (Phantom f, Applicative f) => AFold a a' b b' -> LensLike f a a' b b'@@ -105,7 +112,7 @@ type AGetter a a' b b' = FoldLike b a a' b b' -- | AGetter' a b is a universal Fold' a b instance-type AGetter' a b = AGetter a a b b+type AGetter' a b = FoldLike' b a b -- | Converts a universal getter instance back into a polymorphic getter. cloneGetter :: Phantom f => AGetter a a' b b' -> LensLike f a a' b b'
+ src/Lens/Family/Identical.hs view
@@ -0,0 +1,19 @@+module Lens.Family.Identical where++import Control.Applicative+import Control.Applicative.Backwards (Backwards(..))+import Data.Functor.Identity (Identity(..))+import Data.Functor.Compose (Compose(..))++-- It would really be much better if comonads was in tranformers+class Applicative f => Identical f where+ extract :: f a -> a++instance Identical Identity where+ extract (Identity x) = x++instance Identical f => Identical (Backwards f) where+ extract (Backwards x) = extract x++instance (Identical f, Identical g) => Identical (Compose f g) where+ extract (Compose x) = extract (extract x)
− src/Lens/Family/Setting.hs
@@ -1,12 +0,0 @@-module Lens.Family.Setting where--import Control.Applicative (Applicative, pure, (<*>))--newtype Setting a = Setting { unSetting :: a }--instance Functor Setting where- fmap f (Setting a) = Setting (f a)--instance Applicative Setting where- pure = Setting- Setting f <*> Setting a = Setting (f a)
src/Lens/Family/State/Lazy.hs view
@@ -7,6 +7,7 @@ , (%=) , assign, (.=) , (%%=)+ , (<~) -- * Compound Assignments , (+=), (-=), (*=) , (//=)@@ -16,8 +17,8 @@ , Zooming -- * Re-exports , LensLike, LensLike'- , FoldLike- , Setter, Setter'+ , FoldLike, Constant+ , ASetter, ASetter', Identity , StateT, Writer , Monoid ) where@@ -28,8 +29,8 @@ import Control.Monad.Trans.Writer.Lazy (Writer, writer, runWriter) import Control.Monad.Trans.State.Lazy (StateT(..), state, get, modify) import Lens.Family ( LensLike, LensLike'- , FoldLike- , Setter, Setter'+ , FoldLike, Constant+ , ASetter, ASetter', Identity , view, views, (%~) ) import Lens.Family.State.Zoom (Zooming(..))@@ -84,25 +85,31 @@ -- -- 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 %= -- | Modify a field of the state.-(%=) :: Monad m => Setter a a b b' -> (b -> b') -> StateT a m ()+(%=) :: Monad m => ASetter a a b b' -> (b -> b') -> StateT a m () l %= f = modify (l %~ f) infix 4 .= -- | Set a field of the state.-(.=) :: Monad m => Setter a a b b' -> b' -> StateT a m ()+(.=) :: Monad m => ASetter a a b b' -> b' -> StateT a m () l .= v = l %= const v -- | Set a field of the state.-assign :: Monad m => Setter a a b b' -> b' -> StateT a m ()+assign :: Monad m => ASetter a a b b' -> b' -> StateT a m () assign = (.=) +infixr 2 <~++-- | Set a field of the state using the result of executing a stateful command.+(<~) :: Monad m => ASetter a a b b' -> StateT a m b' -> StateT a m ()+l <~ v = assign l =<< v+ infix 4 %%= (%%=) :: Monad m => LensLike (Writer c) a a b b' -> (b -> (c, b')) -> StateT a m c@@ -121,24 +128,24 @@ infixr 4 +=, -=, *= -(+=), (-=), (*=) :: (Monad m, Num b) => Setter' a b -> b -> StateT a m ()+(+=), (-=), (*=) :: (Monad m, Num b) => ASetter' a b -> b -> StateT a m () f += b = f %= (+ b) f -= b = f %= subtract b f *= b = f %= (* b) infixr 4 //= -(//=) :: (Monad m, Fractional b) => Setter' a b -> b -> StateT a m ()+(//=) :: (Monad m, Fractional b) => ASetter' a b -> b -> StateT a m () f //= b = f %= (/ b) infixr 4 &&=, ||= -(&&=), (||=) :: Monad m => Setter' a Bool -> Bool -> StateT a m ()+(&&=), (||=) :: Monad m => ASetter' a Bool -> Bool -> StateT a m () f &&= b = f %= (&& b) f ||= b = f %= (|| b) infixr 4 <>= -- | Monoidally append a value to all referenced fields of the state.-(<>=) :: (Monoid o, Monad m) => Setter' a o -> o -> StateT a m ()+(<>=) :: (Monoid o, Monad m) => ASetter' a o -> o -> StateT a m () f <>= b = f %= (`mappend` b)
src/Lens/Family/State/Strict.hs view
@@ -7,6 +7,7 @@ , (%=) , assign, (.=) , (%%=)+ , (<~) -- * Compound Assignments , (+=), (-=), (*=) , (//=)@@ -16,8 +17,8 @@ , Zooming -- * Re-exports , LensLike, LensLike'- , FoldLike- , Setter, Setter'+ , FoldLike, Constant+ , ASetter, ASetter', Identity , StateT, Writer , Monoid ) where@@ -28,8 +29,8 @@ import Control.Monad.Trans.Writer.Lazy (Writer, writer, runWriter) import Control.Monad.Trans.State.Strict (StateT(..), state, get, modify) import Lens.Family ( LensLike, LensLike'- , FoldLike- , Setter, Setter'+ , FoldLike, Constant+ , ASetter, ASetter', Identity , view, views, (%~) ) import Lens.Family.State.Zoom (Zooming(..))@@ -84,25 +85,31 @@ -- -- 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 %= -- | Modify a field of the state.-(%=) :: Monad m => Setter a a b b' -> (b -> b') -> StateT a m ()+(%=) :: Monad m => ASetter a a b b' -> (b -> b') -> StateT a m () l %= f = modify (l %~ f) infix 4 .= -- | Set a field of the state.-(.=) :: Monad m => Setter a a b b' -> b' -> StateT a m ()+(.=) :: Monad m => ASetter a a b b' -> b' -> StateT a m () l .= v = l %= const v -- | Set a field of the state.-assign :: Monad m => Setter a a b b' -> b' -> StateT a m ()+assign :: Monad m => ASetter a a b b' -> b' -> StateT a m () assign = (.=) +infixr 2 <~++-- | Set a field of the state using the result of executing a stateful command.+(<~) :: Monad m => ASetter a a b b' -> StateT a m b' -> StateT a m ()+l <~ v = assign l =<< v+ infix 4 %%= (%%=) :: Monad m => LensLike (Writer c) a a b b' -> (b -> (c, b')) -> StateT a m c@@ -121,24 +128,24 @@ infixr 4 +=, -=, *= -(+=), (-=), (*=) :: (Monad m, Num b) => Setter' a b -> b -> StateT a m ()+(+=), (-=), (*=) :: (Monad m, Num b) => ASetter' a b -> b -> StateT a m () f += b = f %= (+ b) f -= b = f %= subtract b f *= b = f %= (* b) infixr 4 //= -(//=) :: (Monad m, Fractional b) => Setter' a b -> b -> StateT a m ()+(//=) :: (Monad m, Fractional b) => ASetter' a b -> b -> StateT a m () f //= b = f %= (/ b) infixr 4 &&=, ||= -(&&=), (||=) :: Monad m => Setter' a Bool -> Bool -> StateT a m ()+(&&=), (||=) :: Monad m => ASetter' a Bool -> Bool -> StateT a m () f &&= b = f %= (&& b) f ||= b = f %= (|| b) infixr 4 <>= -- | Monoidally append a value to all referenced fields of the state.-(<>=) :: (Monoid o, Monad m) => Setter' a o -> o -> StateT a m ()+(<>=) :: (Monoid o, Monad m) => ASetter' a o -> o -> StateT a m () f <>= b = f %= (`mappend` b)
src/Lens/Family/Stock.hs view
@@ -6,26 +6,29 @@ , alongside , 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 , AlongsideLeft, AlongsideRight -- * Re-exports , LensLike, LensLike'- , Applicative+ , Applicative, Identical ) where import Control.Arrow (first, second) import Control.Applicative (Applicative, pure, (<$>), (<*>)) import Lens.Family (LensLike, LensLike')-import Lens.Family.Unchecked (lens)+import Lens.Family.Unchecked (lens, setting, Identical) import Lens.Family.Phantom (Phantom, coerce) import qualified Data.Map as Map import qualified Data.IntMap as IntMap@@ -188,6 +191,14 @@ -- -- The empty traversal on any type. ignored _ = pure++mapped :: (Identical f, Functor g) => LensLike f (g a) (g a') a a'+-- ^ @+-- mapped :: Functor g => Setter (g a) (g a') a a'+-- @+--+-- An SEC referencing the parameter of a functor.+mapped = setting fmap {- Alongside -}
src/Lens/Family/Unchecked.hs view
@@ -79,18 +79,15 @@ , setting -- * Types , LensLike, LensLike'- , Setter, Setter'- , Setting+ , Identical ) where -import Lens.Family.Setting (Setting(..))+import Control.Applicative (pure)+import Lens.Family.Identical (Identical, extract) type LensLike f a a' b b' = (b -> f b') -> (a -> f a') type LensLike' f a b = (b -> f b) -> (a -> f a) -type Setter a a' b b' = LensLike Setting a a' b b'-type Setter' a b = Setter a a b b- lens :: Functor f => (a -> b) -- ^ getter -> (a -> b' -> a') -- ^ setter@@ -128,7 +125,7 @@ iso getter setter = lens getter (const setter) -- | '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 @sec l@.+-- To demote a lens to a semantic edit combinator, use the section @(l %~)@ or @over l@ from "Lens.Family". -- -- >>> setting map . fstL %~ length $ [("The",0),("quick",1),("brown",1),("fox",2)] -- [(3,0),(5,1),(5,1),(3,2)]@@ -138,6 +135,7 @@ -- * @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 s f = Setting . s (unSetting . f)+setting :: Identical f+ => ((b -> b') -> a -> a') -- ^ sec (semantic editor combinator)+ -> LensLike f a a' b b'+setting s f = pure . s (extract . f)