Module
Data.Lens.Index
- Package
- profunctor-lenses
- Repository
- purerl/purescript-profunctor-lenses
#Index Source
class Index m a b | m -> a, m -> b where
Index
is a type class whose instances are optics used when:
- The focus element might not be present.
- You either cannot or do not want to add new elements or delete existing ones.
Array
is a typical example:
preview (ix 1) [0, 1, 2] == Just 1
set (ix 1) 8888 [0, 1, 2] == [0,8888,2]
Note the use of preview
rather view
. That's because the optic is
a Data.Lens.Traversal
tailored to the case where there's a single element
of interest.
Another common use is a Map
that you don't want to either grow or shrink:
(set (ix "k") "new" $ Map.singleton "k" "old") == Map.singleton "k" "new"
(set (ix "k") "new" $ Map.empty) == Map.empty
Note the second line: an attempt to set
a missing focus element
leaves the original whole unchanged.
If you do want to add or delete elements, see Data.Lens.At
.
Members
ix :: a -> AffineTraversal' m b
Instances
- Modules
- Data.
Lens - Data.
Lens. AffineTraversal - Data.
Lens. At - Data.
Lens. Common - Data.
Lens. Fold - Data.
Lens. Fold. Partial - Data.
Lens. Getter - Data.
Lens. Grate - Data.
Lens. Index - Data.
Lens. Indexed - Data.
Lens. Internal. Bazaar - Data.
Lens. Internal. Exchange - Data.
Lens. Internal. Focusing - Data.
Lens. Internal. Forget - Data.
Lens. Internal. Grating - Data.
Lens. Internal. Indexed - Data.
Lens. Internal. Market - Data.
Lens. Internal. Re - Data.
Lens. Internal. Shop - Data.
Lens. Internal. Stall - Data.
Lens. Internal. Tagged - Data.
Lens. Internal. Wander - Data.
Lens. Internal. Zipping - Data.
Lens. Iso - Data.
Lens. Iso. Newtype - Data.
Lens. Lens - Data.
Lens. Lens. Product - Data.
Lens. Lens. Tuple - Data.
Lens. Lens. Unit - Data.
Lens. Lens. Void - Data.
Lens. Prism - Data.
Lens. Prism. Coproduct - Data.
Lens. Prism. Either - Data.
Lens. Prism. Maybe - Data.
Lens. Record - Data.
Lens. Setter - Data.
Lens. Traversal - Data.
Lens. Types - Data.
Lens. Zoom