packages feed

microlens 0.3.0.0 → 0.3.1.0

raw patch · 4 files changed

+69/−5 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Lens.Micro: failing :: Traversal s t a b -> Traversal s t a b -> Traversal s t a b
+ Lens.Micro: instance Applicative (Bazaar a b)
+ Lens.Micro: instance Functor (Bazaar a b)
+ Lens.Micro: type LensLike f s t a b = (a -> f b) -> s -> f t
+ Lens.Micro: type LensLike' f s a = LensLike f s s a a
+ Lens.Micro.Type: type LensLike f s t a b = (a -> f b) -> s -> f t
+ Lens.Micro.Type: type LensLike' f s a = LensLike f s s a a
- Lens.Micro: (<%~) :: ((a -> (b, b)) -> s -> (b, t)) -> (a -> b) -> s -> (b, t)
+ Lens.Micro: (<%~) :: LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
- Lens.Micro: (<<%~) :: ((a -> (a, b)) -> s -> (a, t)) -> (a -> b) -> s -> (a, t)
+ Lens.Micro: (<<%~) :: LensLike ((,) a) s t a b -> (a -> b) -> s -> (a, t)
- Lens.Micro: (<<.~) :: ((a -> (a, b)) -> s -> (a, t)) -> b -> s -> (a, t)
+ Lens.Micro: (<<.~) :: LensLike ((,) a) s t a b -> b -> s -> (a, t)

Files

CHANGELOG.md view
@@ -1,4 +1,9 @@-# unreleased (0.3.0.0)+# 0.3.1.0++* Added `LensLike` and `LensLike'`.+* Added `failing`.++# 0.3.0.0  * Moved `Lens.Micro.Classes` into `Lens.Micro.Internal`. * Added `<%~`, `<<%~`, `<<.~`.
microlens.cabal view
@@ -1,5 +1,5 @@ name:                microlens-version:             0.3.0.0+version:             0.3.1.0 synopsis:            A tiny part of the lens library which you can depend upon description:   This is an extract from <http://hackage.haskell.org/package/lens lens> (with no dependencies). It's not a toy lenses library, unsuitable for “real world”, but merely a small one. It is compatible with lens, and should have same performance. It also has better documentation.
src/Lens/Micro.hs view
@@ -42,6 +42,7 @@    -- * Traversals (lenses iterating over several elements)   Traversal, Traversal',+  failing,   both,   traversed,   each,@@ -52,6 +53,9 @@   -- $prisms-note   _Left, _Right,   _Just, _Nothing,++  -- * Other types+  LensLike, LensLike', ) where @@ -229,7 +233,7 @@ ('<%~') :: 'Monoid' b => 'Traversal' s t a b -> (a -> b) -> s -> (b, t) @ -}-(<%~) :: ((a -> (b, b)) -> s -> (b, t)) -> (a -> b) -> s -> (b, t)+(<%~) :: LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t) (<%~) l f = l (join (,) . f) {-# INLINE (<%~) #-} @@ -246,7 +250,7 @@ ('<<%~') :: 'Monoid' a => 'Traversal' s t a b -> (a -> b) -> s -> (a, t) @ -}-(<<%~) :: ((a -> (a, b)) -> s -> (a, t)) -> (a -> b) -> s -> (a, t)+(<<%~) :: LensLike ((,) a) s t a b -> (a -> b) -> s -> (a, t) (<<%~) l f = l (\a -> (a, f a)) {-# INLINE (<<%~) #-} @@ -263,7 +267,7 @@ ('<<.~') :: 'Monoid' a => 'Traversal' s t a b -> b -> s -> (a, t) @ -}-(<<.~) :: ((a -> (a, b)) -> s -> (a, t)) -> b -> s -> (a, t)+(<<.~) :: LensLike ((,) a) s t a b -> b -> s -> (a, t) (<<.~) l x = l (\a -> (a, x)) {-# INLINE (<<.~) #-} @@ -441,6 +445,40 @@ {-# INLINE lens #-}  -- Traversals --------------------------------------------------------------++{- |+'failing' lets you chain traversals together; if the 1st traversal fails, the 2nd traversal will be used.++>>> ([1,2],[3]) & failing (_1.each) (_2.each) .~ 0+([0,0],[3])++>>> ([],[3]) & failing (_1.each) (_2.each) .~ 0+([],[0])++Note that the resulting traversal won't be valid unless either both traversals don't touch each others' elements, or both traversals return exactly the same results. To see an example of how 'failing' can generate invalid traversals, see <http://stackoverflow.com/questions/27138856/why-does-failing-from-lens-produce-invalid-traversals this Stackoverflow question>.+-}+failing :: Traversal s t a b -> Traversal s t a b -> Traversal s t a b+failing left right afb s = case pins t of+  [] -> right afb s+  _  -> t afb+  where+    Bazaar t = left sell s+    sell w = Bazaar ($ w)+    pins f = getConst (f (\ra -> Const [Identity ra]))++infixl 5 `failing`++newtype Bazaar a b t = Bazaar (forall f. Applicative f => (a -> f b) -> f t)++instance Functor (Bazaar a b) where+  fmap f (Bazaar k) = Bazaar (fmap f . k)+  {-# INLINE fmap #-}++instance Applicative (Bazaar a b) where+  pure a = Bazaar $ \_ -> pure a+  {-# INLINE pure #-}+  Bazaar mf <*> Bazaar ma = Bazaar $ \afb -> mf afb <*> ma afb+  {-# INLINE (<*>) #-}  {- | 'both' traverses both fields of a tuple. Unlike @<http://hackage.haskell.org/package/lens/docs/Control-Lens-Traversal.html#v:both both>@ from lens, it only works for pairs – not for triples or 'Either'.
src/Lens/Micro/Type.hs view
@@ -12,6 +12,7 @@   Getting,   Lens, Lens',   Traversal, Traversal',+  LensLike, LensLike', ) where @@ -169,3 +170,23 @@ This is a type alias for monomorphic traversals which don't change the type of the container (or of the values inside). -} type Traversal' s a = Traversal s s a a++{- |+'LensLike' is a type that is often used to make combinators as general as possible. For instance, take ('Lens.Micro.<<%~'), which only requires the passed lens to be able to work with the @(,) a@ functor (lenses and traversals can do that). The fully expanded type is as follows:++@+('Lens.Micro.<<%~') :: ((a -> (a, b)) -> s -> (a, t)) -> (a -> b) -> s -> (a, t)+@++With 'LensLike', the intent to use the @(,) a@ functor can be made a bit clearer:++@+('Lens.Micro.<<%~') :: LensLike ((,) a) s t a b -> (a -> b) -> s -> (a, t)+@+-}+type LensLike f s t a b = (a -> f b) -> s -> f t++{- |+A type alias for monomorphic 'LensLike's.+-}+type LensLike' f s a = LensLike f s s a a