Traversable

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

Get Learn Scala Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.