Haskell Language Lens Traversals


A Traversal' s a shows that s has 0-to-many as 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]

> over traverse (+1) [1..10]

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 bs 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 bs in s.