@@ -16,7 +16,26 @@ fully interoperable with the combinators found in mainstream lens libraries.
17Examples can be found in the `examples` and `tests` folders.
17Examples can be found in the `examples` and `tests` folders.
22+* [Preliminaries](#preliminaries)
23+* [Taxonomy of optics](#taxonomy-of-optics)
25+ * [By name](#by-name-1)
26+ * [By position](#by-position)
27+ * [By type](#by-type-1)
28+ * [By structure](#by-structure)
29+ * [Traversals](#traversals)
30+ * [By type](#by-type-2)
31+ * [By parameter](#by-parameter)
32+ * [By constraint](#by-constraint)
34+ * [By name](#by-name-2)
35+ * [By type](#by-type-3)
36+* [Contributors](#contributors)
19−## Preliminaries
38+# Preliminaries
20A typical module using `generic-lens` will usually have the following
39A typical module using `generic-lens` will usually have the following
21extensions turned on:
40extensions turned on:
@@ -31,7 +50,7 @@ extensions turned on:
32# Taxonomy of optics
51# Taxonomy of optics
33Here is a comprehensive list of the optics exposed by `generic-lens`. The
52Here is a comprehensive list of the optics exposed by `generic-lens`. The
34−combinators each allows a different way of identifying certain parts of
53+combinators each allow a different way of identifying certain parts of
35algebraic data types.
54algebraic data types.
@@ -80,7 +99,10 @@ error:
81For types with multiple constructors, we can still use `field` as long as all constructors contain the required field
100For types with multiple constructors, we can still use `field` as long as all constructors contain the required field
82```haskell
101```haskell
83−data Two = First { wurble :: String, banana :: Int } | Second { wurble :: String } deriving (Generic, Show)
103+ = First { wurble :: String, banana :: Int }
104+ | Second { wurble :: String }
105+ deriving (Generic, Show)
85>>> Second "woops" ^. field @"wurble"
107>>> Second "woops" ^. field @"wurble"
@@ -113,7 +135,9 @@ foo1 = Foo (Just 10)
113foo2 :: Foo [] String
135foo2 :: Foo [] String
114foo2 = foo1 & field @"foo" %~ (maybeToList . fmap show)
136foo2 = foo1 & field @"foo" %~ (maybeToList . fmap show)
116−This example shows that higher-kinded parameters can also be changed (`Maybe` -> `[]`).
138+This example shows that higher-kinded parameters can also be changed (`Maybe`
139+-> `[]`). We turn a `Foo Maybe Int` into a `Foo [] String` by turning the inner
140+`Maybe Int` into a `[String]`.
118### By position
142### By position
@@ -304,7 +328,7 @@ error:
307−## Contributors
331+# Contributors
309+ [Matthew Pickering](https://github.com/mpickering)
333+ [Matthew Pickering](https://github.com/mpickering)
310+ [Toby Shaw](https://github.com/TobyShaw)
334+ [Toby Shaw](https://github.com/TobyShaw)