2. Software Developer at codecentric
Co-organizer of ScalaDus and
IdrisDus
Maintainer of cats, cats-effect,
cats-mtl, OutWatch
Enthusiastic about FP
About me
3. Motivation
● Traversable is my favorite type class
● Not enough people know about it
● Even less people know about some of the less common traversals out there
● Have some fun while learning!
5. Teaser
How do you create a List of Http Requests run them all in parallel and if errors
occur accumulate them?
userIdList.parTraverse(request).value
7. Traverse
[T[_]: Traverse, F[_]: Applicative, A]: T[F[A]] => F[T[A]]
Traverse runs an action(F[_]) for every element in a data structure (T[_]), and
accumulates the results.
8. Traverse
trait Applicative[F[_]] {
def map2[A, B, C](fa: F[A], fb: F[B])(f: (A, B) => C): F[C]
def pure[A](a: A): F[A]
}
Applicatives allow us to combine two or more independent values inside a
context.
28. Summary
Traverse is a great abstraction, because it allows us to traverse data structures
using Applicative Functors, which represent independent computations.
These traversals capture the essence of imperative loops over these data
structures.
We can add or remove constraints to the action(F[_]) or the structure types(T[_])
to get slightly different traversals.
29. Thank you all for
listening!
Twitter:
@LukaJacobowitz
GitHub:
LukaJCB