/ totd

TOTD: Scala - Traversing

Sequencing is when you traverse over a collection's identity. It's not obvious but the purpose is to go from F[G[A]] to G[F[A]].

xs.sequence == xs.traverse(identity)

It's a great idea to internalize the following:

xs.map(f).sequence == xs.map(f).traverse(identity) == xs.traverse(f)

The reason this is so is because map and sequence are defined in terms of traverse in Cats.

When you find yourself flattening after a traverse, use flatSequence.