packages feed

microlens 0.1.1.0 → 0.1.2.0

raw patch · 3 files changed

+178/−149 lines, 3 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Lens.Micro: class Each s t a b | s -> a, t -> b, s b -> t, t a -> s where each = traverse
+ Lens.Micro: each :: Each s t a b => Traversal s t a b
+ Lens.Micro: instance (a ~ b, a ~ c, a ~ d, a ~ e, q ~ r, q ~ s, q ~ t, q ~ u) => Each (a, b, c, d, e) (q, r, s, t, u) a q
+ Lens.Micro: instance (a ~ b, a ~ c, a ~ d, q ~ r, q ~ s, q ~ t) => Each (a, b, c, d) (q, r, s, t) a q
+ Lens.Micro: instance (a ~ b, a ~ c, q ~ r, q ~ s) => Each (a, b, c) (q, r, s) a q
+ Lens.Micro: instance (a ~ b, q ~ r) => Each (a, b) (q, r) a q
+ Lens.Micro: instance Each (Complex a) (Complex b) a b
+ Lens.Micro: instance Each (Maybe a) (Maybe b) a b
+ Lens.Micro: instance Each [a] [b] a b

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.1.2.0++* Added `each`.+ # 0.1.1.0  * Added `ASetter'`, which is useful because we can't provide real `Setter` and `Setter'`.
microlens.cabal view
@@ -1,11 +1,11 @@ name:                microlens-version:             0.1.1.0+version:             0.1.2.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.+  “real world”, but merely a small one. It is compatible with lens, and+  should have same performance. It also has better documentation.   .   Use this library:   .@@ -27,6 +27,9 @@   .   Note that microlens has /no/ dependencies starting from GHC 7.10    (base-4.8). Prior to that, it has to depend on transformers-0.2 or above.+  .+  Also note that it's not done yet and there's a lot of things missing+  and I'm still writing a tutorial for it. license:             BSD3 license-file:        LICENSE author:              Artyom@@ -57,6 +60,11 @@   if !impl(ghc>=7.9)     build-depends:     base >=4.4 && <5                      , transformers >=0.2++  ghc-options:+    -Wall -fwarn-tabs+    -O2 -fdicts-cheap -funbox-strict-fields+    -fmax-simplifier-iterations=10    hs-source-dirs:      src   default-language:    Haskell2010
src/Lens/Micro.hs view
@@ -1,17 +1,21 @@ {-# LANGUAGE-  CPP-, MultiParamTypeClasses-, FunctionalDependencies-, FlexibleInstances-, FlexibleContexts-, RankNTypes-, ScopedTypeVariables+CPP,+MultiParamTypeClasses,+FunctionalDependencies,+FlexibleInstances,+FlexibleContexts,+DefaultSignatures,+GADTs,+UndecidableInstances,+RankNTypes,+ScopedTypeVariables   #-}   module Lens.Micro (   (&),+  -- $ampersand-note    -- * Setting (applying a function to values)   ASetter, ASetter',@@ -36,15 +40,18 @@   Lens, Lens',   lens, -  -- * Traversals (lenses which have multiple targets)+  -- * Traversals (lenses which iterate over several elements)   Traversal, Traversal',   both, -  -- * Prisms+  -- * Prisms (traversals which iterate over at most 1 element)   -- $prisms-note   _Left, _Right,   _Just, _Nothing, +  -- * Each (an universal traversal for various structures)+  Each(..),+     -- * Tuples   Field1(..),   Field2(..),@@ -57,9 +64,14 @@  import Control.Applicative import Data.Functor.Identity-import Data.Foldable import Data.Monoid+import Data.Complex +#if __GLASGOW_HASKELL__ < 710+import Data.Foldable+import Data.Traversable+#endif+ #if __GLASGOW_HASKELL__ >= 710 import Data.Function ((&)) #endif@@ -73,9 +85,7 @@  #if __GLASGOW_HASKELL__ < 710 {- |-'&' is a reverse application operator. This provides notational-convenience. Its precedence is one higher than that of the forward-application operator '$', which allows '&' to be nested in '$'.+'&' is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator '$', which allows '&' to be nested in '$'. -} (&) :: a -> (a -> b) -> b a & f = f a@@ -83,13 +93,34 @@ infixl 1 & #endif +{- $ampersand-note++This operator is useful when you want to modify something several times. For instance, if you want to change 1st and 3rd elements of a tuple, you can write this:++@+(1,2,3) '&' '_1' '.~' 0+        '&' '_3' '%~' 'negate'+@++instead of e.g. this:++@+('_1' '.~' 0) '.' ('_3' '%~' 'negate') '$' (1,2,3)+@++or this:++@+'set' '_1' 0 '.'+'over' '_3' 'negate'+  '$' (1,2,3)+@+-}+ -- Setting -----------------------------------------------------------------  {- |-@ASetter s t a b@ is something that turns a function modifying a value-into a function modifying a /structure/. If you ignore-'Control.Monad.Identity.Identity' (as @Identity a@ is the same thing as @a@),-the type is:+@ASetter s t a b@ is something that turns a function modifying a value into a function modifying a /structure/. If you ignore 'Identity' (as @Identity a@ is the same thing as @a@), the type is:  @ type ASetter s t a b = (a -> b) -> s -> t@@ -109,40 +140,30 @@      (which corresponds to '_1') -  * @'Control.Arrow.left' :: (a -> b) -> Either a x -> Either b x@+  * @'Control.Arrow.left' :: (a -> b) -> 'Either' a x -> 'Either' b x@      (which corresponds to '_Left') -The reason 'Control.Monad.Identity.Identity' is used here is for 'ASetter' to-be composable with other types, such as 'Lens'.+The reason 'Identity' is used here is for 'ASetter' to be composable with other types, such as 'Lens'. -Technically, if you're writing a library, you shouldn't use this type for-setters you are exporting from your library; the right type to use is-@Setter@, but it is not provided by microlens. It's completely alright,-however, to export functions which take an 'ASetter' as an argument.+Technically, if you're writing a library, you shouldn't use this type for setters you are exporting from your library; the right type to use is @<http://hackage.haskell.org/package/lens/docs/Control-Lens-Setter.html#t:Setter Setter>@, but it is not provided by this package (because then we'd have to depend on <http://hackage.haskell.org/package/distributive distributive>). It's completely alright, however, to export functions which take an 'ASetter' as an argument. -} type ASetter s t a b = (a -> Identity b) -> s -> Identity t  {- |-This is a type alias for monomorphic setters which don't change the type of-the container (or of the value inside). It's useful more often than the same-type in lens, because we can't provide real setters and so it does the job of-both @ASetter'@ and @Setter'@.+This is a type alias for monomorphic setters which don't change the type of the container (or of the value inside). It's useful more often than the same type in lens, because we can't provide real setters and so it does the job of both @ASetter'@ and @Setter'@. -} type ASetter' s a = ASetter s s a a  {- |-'sets' creates an 'ASetter' from an ordinary function. (The only thing it-does is wrapping and unwrapping 'Control.Monad.Identity.Identity'.)+'sets' creates an 'ASetter' from an ordinary function. (The only thing it does is wrapping and unwrapping 'Identity'.) -} sets :: ((a -> b) -> s -> t) -> ASetter s t a b sets f g = Identity . f (runIdentity . g) {-# INLINE sets #-}  {- |-('%~') applies a function to the target; an alternative explanation is that-it is an inverse of 'sets', which turns a setter into an ordinary-function. @'mapped' '%~' reverse@ is the same thing as @'fmap' reverse@.+('%~') applies a function to the target; an alternative explanation is that it is an inverse of 'sets', which turns a setter into an ordinary function. @'mapped' '%~' 'reverse'@ is the same thing as @'fmap' 'reverse'@.  See 'over' if you want a non-operator synonym. @@ -191,10 +212,8 @@ {- | ('.~') assigns a value to the target. These are equivalent: -@-l '.~' x-l '%~' 'const' x-@+* @l '.~' x@+* @l '%~' 'const' x@  See 'set' if you want a non-operator synonym. @@ -231,17 +250,14 @@ {-# INLINE set #-}  {- |-'mapped' is a setter for everything contained in a functor. You can use it-to map over lists, @Maybe@, or even @IO@ (which is something you can't do-with 'traversed' or 'each').+'mapped' is a setter for everything contained in a functor. You can use it to map over lists, @Maybe@, or even @IO@ (which is something you can't do with 'traverse' or 'each').  Here 'mapped' is used to turn a value to all non-'Nothing' values in a list:  >>> [Just 3,Nothing,Just 5] & mapped.mapped .~ 0 [Just 0,Nothing,Just 0] -Keep in mind that while 'mapped' is a more powerful setter than 'each', it-can't be used as a getter! This won't work (and will fail with a type error):+Keep in mind that while 'mapped' is a more powerful setter than 'each', it can't be used as a getter! This won't work (and will fail with a type error):  @ [(1,2),(3,4),(5,6)] '^..' 'mapped' . 'both'@@ -255,26 +271,26 @@  {- $getters-note -Getters are a not-entirely-obvious way to use (supposedly) /value-changing/-traversals to /carry out/ information from a structure. For details, see the-documentation for 'Getting'.+Getters are a not-entirely-obvious way to use lenses to /carry out/ information from a structure (instead of changing something inside the structure). Any lens or traversal is a getter. -Exporting @Getter@ is impossible, as then microlens would have to depend on-contravariant.+For details, see the documentation for 'Getting'.++Including @<http://hackage.haskell.org/package/lens/docs/Control-Lens-Getter.html#t:Getter Getter>@ is impossible, as then this package would have to depend on <http://hackage.haskell.org/package/contravariant contravariant> and it's a big dependency. -}  {- |-@Getting r s a@ is, in a way, equivalent to @s -> a@. Since @'Const' r a@ is-the same as @r@, 'Getting' is actually @(a -> r) -> s -> r@, which is just-CPS-transformed @s -> a@. The reason 'Const' and CPS are used is that we want-getters to have the same shape as lenses (which we achieve because 'Const' is-a functor).+If you take a lens or a traversal and choose @'Const' r@ as your functor, you will get @Getting r s a@. This can be used to get something out of the structure instead of modifying it:++@+s '^.' l = 'getConst' (l 'Const' s)+@++Functions that operate on getters – such as ('^.'), ('^..'), ('^?') – use @Getter r s a@ (with different values of @r@) to describe what kind of getter they need. For instance, ('^.') needs the getter to be able to return a single value, and so it accepts a getter of type @Getting a s a@. ('^..') wants the getter to gather values together, so it uses @Getting (Endo [a]) s a@ (it could've used @Getting [a] s a@ instead, but it's faster with 'Endo'). The choice of @r@ depends on what you want to do with elements you're extracting from @s@. -} type Getting r s a = (a -> Const r a) -> s -> Const r s  {- |-('^.') applies a getter to a value; in other words, it gets a value out of a-structure using a getter (which can be a lens, traversal, fold, etc.).+('^.') applies a getter to a value; in other words, it gets a value out of a structure using a getter (which can be a lens, traversal, fold, etc.).  Getting 1st field of a tuple: @@ -283,16 +299,12 @@ ('^.' '_1') = 'fst' @ -When ('^.') is used with a traversal, it combines all results using the-'Monoid' instance for the resulting type. For instance, for lists it would be-simple concatenation:+When ('^.') is used with a traversal, it combines all results using the 'Monoid' instance for the resulting type. For instance, for lists it would be simple concatenation:  >>> ("str","ing") ^. each "string" -The reason for this is that traversals use 'Applicative', and the-'Applicative' instance for 'Const' uses monoid concatenation to combine-“effects” of 'Const'.+The reason for this is that traversals use 'Applicative', and the 'Applicative' instance for 'Const' uses monoid concatenation to combine “effects” of 'Const'. -} (^.) :: s -> Getting a s a -> a s ^. l = getConst (l Const s)@@ -338,9 +350,7 @@ {-# INLINE toListOf #-}  {- |-@s ^? t@ returns the 1st element @t@ returns, or 'Nothing' if @t@ doesn't-return anything. It's trivially implemented by passing the 'First' monoid to-the getter.+@s ^? t@ returns the 1st element @t@ returns, or 'Nothing' if @t@ doesn't return anything. It's trivially implemented by passing the 'First' monoid to the getter.  Safe 'head': @@ -365,8 +375,7 @@ infixl 8 ^?  {- |-('^?!') is an unsafe variant of ('^?') – instead of using 'Nothing' to-indicate that there were no elements returned, it throws an exception.+('^?!') is an unsafe variant of ('^?') – instead of using 'Nothing' to indicate that there were no elements returned, it throws an exception. -} (^?!) :: s -> Getting (Endo a) s a -> a s ^?! l = foldrOf l const (error "(^?!): empty Fold") s@@ -391,17 +400,14 @@ {-# INLINE folded #-}  {- |-'has' checks whether a getter (any getter, including lenses, traversals, and-folds) returns at least 1 value.+'has' checks whether a getter (any getter, including lenses, traversals, and folds) returns at least 1 value.  Checking whether a list is non-empty:  >>> has each [] False -You can also use it with e.g. '_Left' (and other 0-or-1 traversals) as a-replacement for 'Data.Maybe.isNothing', 'Data.Maybe.isJust' and other-@isConstructorName@ functions:+You can also use it with e.g. '_Left' (and other 0-or-1 traversals) as a replacement for 'Data.Maybe.isNothing', 'Data.Maybe.isJust' and other @isConstructorName@ functions:  >>> has _Left (Left 1) True@@ -413,23 +419,16 @@ -- Lenses ------------------------------------------------------------------  {- |-Lenses in a nutshell: use ('^.') to get, ('.~') to set, ('%~') to-modify. ('.')  composes lenses (i.e. if a @B@ is a part of @A@, and a @C@ is-a part of in @B@, then @b.c@ lets you operate on @C@ inside @A@). You can-create lenses with 'lens', or you can write them by hand (see below).+Lenses in a nutshell: use ('^.') to get, ('.~') to set, ('%~') to modify. ('.') composes lenses (i.e. if a @B@ is a part of @A@, and a @C@ is a part of in @B@, then @b.c@ lets you operate on @C@ inside @A@). You can create lenses with 'lens', or you can write them by hand (see below). -@Lens s t a b@ is the lowest common denominator of a setter and a getter,-something that has the power of both; it has a 'Functor' constraint, and-since both 'Const' and 'Control.Monad.Identity.Identity' are functors, it can-be used whenever a getter or a setter is needed.+@Lens s t a b@ is the lowest common denominator of a setter and a getter, something that has the power of both; it has a 'Functor' constraint, and since both 'Const' and 'Identity' are functors, it can be used whenever a getter or a setter is needed.    * @a@ is the type of the value inside of structure   * @b@ is the type of the replaced value   * @s@ is the type of the whole structure   * @t@ is the type of the structure after replacing @a@ in it with @b@ -A 'Lens' can only point at a single value inside a structure (unlike a-'Traversal').+A 'Lens' can only point at a single value inside a structure (unlike a 'Traversal').  It is easy to write lenses manually. The generic template is: @@ -451,12 +450,11 @@ Here's the '_1' lens:  @-_1 :: Lens (a, x) (b, x) a b-_1 f (a, x) = (\\b -> (b, x)) '<$>' f a+'_1' :: 'Lens' (a, x) (b, x) a b+'_1' f (a, x) = (\\b -> (b, x)) '<$>' f a @ -Here's a more complicated lens, which extracts /several/ values from a-structure (in a tuple):+Here's a more complicated lens, which extracts /several/ values from a structure (in a tuple):  @ type Age     = Int@@ -471,11 +469,7 @@   (\\(city', country') -> Person age city' country') '<$>' f (city, country) @ -You even can choose to use a lens to present /all/ information contained in-the structure (in a different way). Such lenses are called @Iso@ in lens's-terminology. For instance (assuming you don't mind functions that can error-out), here's a lens which lets you act on the string representation of a-value:+You even can choose to use a lens to present /all/ information contained in the structure (in a different way). Such lenses are called @Iso@ in lens's terminology. For instance (assuming you don't mind functions that can error out), here's a lens which lets you act on the string representation of a value:  @ string :: (Read a, Show a) => 'Lens'' a String@@ -492,15 +486,12 @@ type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t  {- |-This is a type alias for monomorphic lenses which don't change the type of-the container (or of the value inside).+This is a type alias for monomorphic lenses which don't change the type of the container (or of the value inside). -} type Lens' s a = Lens s s a a  {- |-'lens' creates a 'Lens' from a getter and a setter. The resulting lens isn't-the most effective one (because of having to traverse the structure twice-when modifying), but it shouldn't matter much.+'lens' creates a 'Lens' from a getter and a setter. The resulting lens isn't the most effective one (because of having to traverse the structure twice when modifying), but it shouldn't matter much.  A (partial) lens for list indexing: @@ -520,11 +511,7 @@ [1,2,3,-4,5,6,7,8,9] @ -When getting, the setter is completely unused. When setting, the getter is-unused. Both are used only when the value is being modified.--Here's an example of using a lens targeting the head of a list. The getter is-replaced with 'undefined' to make sure it's not used:+When getting, the setter is completely unused; when setting, the getter is unused. Both are used only when the value is being modified. For instance, here we define a lens for the 1st element of a list, but instead of a legitimate getter we use 'undefined'. Then we use the resulting lens for /setting/ and it works, which proves that the getter wasn't used:  >>> [1,2,3] & lens undefined (\s b -> b : tail s) .~ 10 [10,2,3]@@ -536,31 +523,19 @@ -- Traversals --------------------------------------------------------------  {- |-Traversals in a nutshell: they're like lenses but they can point at multiple-values. Use ('^..') (not '^.') to get all values, ('^?') to get the 1st-value, ('.~') to set values, ('%~') to modify them. ('.') composes traversals-just as it composes lenses.+Traversals in a nutshell: they're like lenses but they can point at multiple values. Use ('^..') to get all values, ('^?') to get the 1st value, ('.~') to set values, ('%~') to modify them. ('.') composes traversals just as it composes lenses. ('^.') can be used with traversals as well, but don't confuse it with ('^..'). -@Traversal s t a b@ is a generalisation of 'Lens' which allows many targets-(possibly 0). It's achieved by changing the constraint to 'Applicative'-instead of 'Functor' – indeed, the point of 'Applicative' is that you can-combine effects, which is just what we need to have many targets.+@Traversal s t a b@ is a generalisation of 'Lens' which allows many targets (possibly 0). It's achieved by changing the constraint to 'Applicative' instead of 'Functor' – indeed, the point of 'Applicative' is that you can combine effects, which is just what we need to have many targets. -Traversals don't differ from lenses when it comes to setting – you can use-usual ('%~') and ('.~') to modify and set values. Getting is a bit different,-because you have to decide what to do in the case of multiple values. In-particular, you can use these combinators (as well as everything else in the-“Folds” section):+Traversals don't differ from lenses when it comes to setting – you can use usual ('%~') and ('.~') to modify and set values. Getting is a bit different, because you have to decide what to do in the case of multiple values. In particular, you can use these combinators (as well as everything else in the “Folds” section):    * ('^..') gets a list of values   * ('^?') gets the 1st value (or 'Nothing' if there are no values)   * ('^?!') gets the 1st value and throws an exception if there are no values -In addition, ('^.') works for traversals as well – it combines traversed-values using the ('<>') operation (if the values are instances of 'Monoid').+In addition, ('^.') works for traversals as well – it combines traversed values using the ('<>') operation (if the values are instances of 'Monoid'). -Traversing any value twice is a violation of traversal laws. You can,-however, traverse values in any order.+Traversing any value twice is a violation of traversal laws. You can, however, traverse values in any order.  Ultimately, traversals should follow 2 laws: @@ -569,26 +544,17 @@ fmap (t f) . t g ≡ getCompose . t (Compose . fmap f . g) @ -The 1st law states that you can't change the shape of the structure or do-anything funny with elements (traverse elements which aren't in the-structure, create new elements out of thin air, etc.). The 2nd law states-that you should be able to fuse 2 identical traversals into one. For a more-detailed explanation of the laws, see-<http://artyom.me/lens-over-tea-2#traversal-laws this blog post> (if you-prefer rambling blog posts), or-<https://www.cs.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf The Essence Of The Iterator Pattern> (if you prefer papers).+The 1st law states that you can't change the shape of the structure or do anything funny with elements (traverse elements which aren't in the structure, create new elements out of thin air, etc.). The 2nd law states that you should be able to fuse 2 identical traversals into one. For a more detailed explanation of the laws, see <http://artyom.me/lens-over-tea-2#traversal-laws this blog post> (if you prefer rambling blog posts), or <https://www.cs.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf The Essence Of The Iterator Pattern> (if you prefer papers). -} type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t  {- |-This is a type alias for monomorphic traversals which don't change the type-of the container (or of the values inside).+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  {- |-'both' traverses both fields of a tuple. Unlike @both@ from lens, it only-works for pairs – not for triples or 'Either'.+'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'.  >>> ("str","ing") ^. both "string"@@ -604,9 +570,7 @@  {- $prisms-note -Prisms are traversals which always target 0 or 1 values. Moreover, it's-possible to /reverse/ a prism, using it to construct a structure instead of-peeking into it. Here's an example from the lens library:+Prisms are traversals which always target 0 or 1 values. Moreover, it's possible to /reverse/ a prism, using it to construct a structure instead of peeking into it. Here's an example from the lens library:  @ >>> over _Left (+1) (Left 2)@@ -616,10 +580,7 @@ Left 5 @ -However, it's not possible for microlens to export prisms, because their type-depends on @Choice@, which resides in the profunctors library, which is a-somewhat huge dependency. So, all prisms included here are traversals-instead.+However, it's not possible for microlens to export prisms, because their type depends on @<http://hackage.haskell.org/package/profunctors/docs/Data-Profunctor.html#t:Choice Choice>@, which resides in the <http://hackage.haskell.org/package/profunctors profunctors> library, which is a somewhat huge dependency. So, all prisms included here are traversals instead. -}  {- |@@ -675,8 +636,7 @@ {- | '_Just' targets the value contained in a 'Maybe', provided it's a 'Just'. -See documentation for '_Left' (as these 2 are pretty similar). In particular,-it can be used to write these:+See documentation for '_Left' (as these 2 are pretty similar). In particular, it can be used to write these:    * Unsafely extracting a value from a 'Just': @@ -708,8 +668,7 @@ {-# INLINE _Just #-}  {- |-'_Nothing' targets a @()@ if the 'Maybe' is a 'Nothing', and doesn't target-anything otherwise:+'_Nothing' targets a @()@ if the 'Maybe' is a 'Nothing', and doesn't target anything otherwise:  >>> Just 1 ^.. _Nothing []@@ -717,8 +676,7 @@ >>> Nothing ^.. _Nothing [()] -It's not particularly useful (unless you want to use @'has' '_Nothing'@ as a-replacement for 'Data.Maybe.isNothing'), and provided mainly for consistency.+It's not particularly useful (unless you want to use @'has' '_Nothing'@ as a replacement for 'Data.Maybe.isNothing'), and provided mainly for consistency.  Implementation: @@ -732,6 +690,66 @@ _Nothing _ j = pure j {-# INLINE _Nothing #-} +-- Each++{- |+A class to support 'each'. If you're writing a library, don't write instances of this class which would be exported – other users won't be able to use them if they use lens.+-}+class Each s t a b | s -> a, t -> b, s b -> t, t a -> s where+  {- |+'each' tries to be a universal 'Traversal' – it behaves like 'traverse' in most situations, but also adds support for e.g. tuples with same-typed values:++>>> (1,2) & each %~ succ+(2,3)++>>> ["x", "y", "z"] ^. each+"xyz"++However, note that 'each' doesn't work on /every/ instance of 'Traversable'. If you have a 'Traversable' which isn't supported by 'each', you can use 'traverse' instead. Personally, I like using 'each' instead of 'traverse' whenever possible – it's shorter and more descriptive.++You can use 'each' with these things:++@+'each' :: 'Traversal' [a] [b] a b++'each' :: 'Traversal' ('Maybe' a) ('Maybe' b) a b++'each' :: 'Traversal' (a,a) (b,b) a b+'each' :: 'Traversal' (a,a,a) (b,b,b) a b+'each' :: 'Traversal' (a,a,a,a) (b,b,b,b) a b+'each' :: 'Traversal' (a,a,a,a,a) (b,b,b,b,b) a b++'each' :: ('RealFloat' a, 'RealFloat' b) => 'Traversal' ('Complex' a) ('Complex' b) a b+@+  -}+  each :: Traversal s t a b+  default each :: (Traversable g, s ~ g a, t ~ g b) => Traversal s t a b+  each = traverse++instance (a~b, q~r) => Each (a,b) (q,r) a q where+  each f ~(a,b) = (,) <$> f a <*> f b+  {-# INLINE each #-}++instance (a~b, a~c, q~r, q~s) => Each (a,b,c) (q,r,s) a q where+  each f ~(a,b,c) = (,,) <$> f a <*> f b <*> f c+  {-# INLINE each #-}++instance (a~b, a~c, a~d, q~r, q~s, q~t) => Each (a,b,c,d) (q,r,s,t) a q where+  each f ~(a,b,c,d) = (,,,) <$> f a <*> f b <*> f c <*> f d+  {-# INLINE each #-}++instance (a~b, a~c, a~d, a~e, q~r, q~s, q~t, q~u) => Each (a,b,c,d,e) (q,r,s,t,u) a q where+  each f ~(a,b,c,d,e) = (,,,,) <$> f a <*> f b <*> f c <*> f d <*> f e+  {-# INLINE each #-}++instance Each (Complex a) (Complex b) a b where+  each f (a :+ b) = (:+) <$> f a <*> f b+  {-# INLINE each #-}++instance Each [a] [b] a b++instance Each (Maybe a) (Maybe b) a b+ -- Tuples ------------------------------------------------------------------  -- Commented instances amount to ~0.8s of building time.@@ -755,8 +773,7 @@ >>> set _1 10 undefined :: (Int, Int) (10,*** Exception: Prelude.undefined -This is done to avoid violating a lens law stating that you can get-back what you put:+This is done to avoid violating a lens law stating that you can get back what you put:  >>> view _1 . set _1 10 $ (undefined :: (Int, Int)) 10@@ -764,8 +781,8 @@ The implementation (for 2-tuples) is:  @-'_1' f t = (,) '<$>' f    (fst t)-             '<*>' 'pure' (snd t)+'_1' f t = (,) '<$>' f    ('fst' t)+             '<*>' 'pure' ('snd' t) @  or, alternatively,@@ -774,7 +791,7 @@ '_1' f ~(a,b) = (\\a' -> (a',b)) '<$>' f a @ -(where @~@ means a lazy pattern).+(where @~@ means a <https://wiki.haskell.org/Lazy_pattern_match lazy pattern>).   -}   _1 :: Lens s t a b