The Traversable functor is similar to Reducible and Foldable, which we talked about in the previous chapter. The difference is that methods defined on Traversable preserve the underlying structure while going over it, as opposed to the other abstractions which collapse it into the single result. The Traversable defines two methods:
import scala.{ Traversable => _ }
trait Traversable[F[_]] extends Functor[F] {
def sequence[A,G[_]: Applicative](a: F[G[A]]): G[F[A]]
def traverse[A,B,G[_]: Applicative](a: F[A])(f: A => G[B]): G[F[B]]
}
Unfortunately, Scala has a deprecated Traversable definition left over from previous versions, so we are getting rid of it by using import renaming. Our Traversable defines the sequence and traverse methods, which loosely correspond to the reduce and fold methods defined on monoids. Starting with the sequence method, we can see that...