Data.Lens.Traversal
- Package
- purescript-profunctor-lenses
- Repository
- purescript-contrib/purescript-profunctor-lenses
Traversal
is an optic that focuses on zero or more values. An
Array
would be a typical example:
over traversed negate [1, 2, 3] == [-1, -2, -3]
preview traversed [1, 2, 3] == Just 1
firstOf traversed [1, 2, 3] == Just 1 -- same as `preview`
lastOf traversed [1, 2, 3] == Just 3
view
might surprise you. It assumes that the wrapped values
are a monoid, and append
s them together:
view traversed ["D", "a", "w", "n"] == "Dawn"
Many of the functions you'll use are documented in Data.Lens.Fold
.
#traversed Source
traversed :: forall t a b. Traversable t => Traversal (t a) (t b) a b
A Traversal
for the elements of a Traversable
functor.
over traversed negate [1, 2, 3] == [-1,-2,-3]
over traversed negate (Just 3) == Just -3
#element Source
element :: forall p s t a. Wander p => Int -> Traversal s t a a -> Optic p s t a a
Combine an index and a traversal to narrow the focus to a single
element. Compare to Data.Lens.Index
.
set (element 2 traversed) 8888 [0, 0, 3] == [0, 0, 8888]
preview (element 2 traversed) [0, 0, 3] == Just 3
The resulting traversal is called an affine traversal, which means that the traversal focuses on one or zero (if the index is out of range) results.
#traverseOf Source
traverseOf :: forall f s t a b. Optic (Star f) s t a b -> (a -> f b) -> s -> f t
Turn a pure profunctor Traversal
into a lens
-like Traversal
.
#sequenceOf Source
sequenceOf :: forall f s t a. Optic (Star f) s t (f a) a -> s -> f t
Sequence the foci of an optic, pulling out an "effect".
If you do not need the result, see sequenceOf_
for Fold
s.
sequenceOf traversed
has the same result as Data.Traversable.sequence
:
sequenceOf traversed (Just [1, 2]) == [Just 1, Just 2]
sequence (Just [1, 2]) == [Just 1, Just 2]
An example with effects:
> array = [random, random]
> :t array
Array (Eff ... Number)
> effect = sequenceOf traversed array
> :t effect
Eff ... (Array Number)
> effect >>= logShow
[0.15556037108154985,0.28500369615270515]
unit
#elementsOf Source
elementsOf :: forall p i s t a. Wander p => IndexedTraversal i s t a a -> (i -> Boolean) -> IndexedOptic p i s t a a
Traverse elements of an IndexedTraversal
whose index satisfy a predicate.
#itraverseOf Source
itraverseOf :: forall f i s t a b. IndexedOptic (Star f) i s t a b -> (i -> a -> f b) -> s -> f t
Turn a pure profunctor IndexedTraversal
into a lens
-like IndexedTraversal
.
#iforOf Source
iforOf :: forall f i s t a b. IndexedOptic (Star f) i s t a b -> s -> (i -> a -> f b) -> f t
Flipped version of itraverseOf
.
#cloneTraversal Source
cloneTraversal :: forall s t a b. ATraversal s t a b -> Traversal s t a b
#both Source
both :: forall r a b. Bitraversable r => Traversal (r a a) (r b b) a b
Re-exports from Data.Lens.Types
#Traversal' Source
type Traversal' s a = Traversal s s a a
- 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