A Traversal' s a
shows that s
has 0-to-many a
s inside of it.
toListOf :: Traversal' s a -> (s -> [a])
Any type t
which is Traversable
automatically has that traverse :: Traversal (t a) a
.
We can use a Traversal
to set or map over all of these a
values
> set traverse 1 [1..10]
[1,1,1,1,1,1,1,1,1,1]
> over traverse (+1) [1..10]
[2,3,4,5,6,7,8,9,10,11]
A f :: Lens' s a
says there's exactly one a
inside of s
. A g :: Prism' a b
says there are either 0 or 1 b
s in a
. Composing f . g
gives us a Traversal' s b
because following f
and then g
shows how there there are 0-to-1 b
s in s
.