The tailRecM method

Previously in this section, we touched on the tailRecM method briefly. It is pretty useful in certain situations, because it allows you to define loops in the context of an effect type. In this subsection, let's take a more detailed look at its signature and at how this method works:

Let's take a look at the arguments of this method. First of all, let's take a look at the second argument of this method, the f function. The function takes a raw value of type A, and the result of this function is an effect type, which is F[Either[A, B]].

Let's think about what we can do with this computation to make a loop out of it. Suppose ...

Get Mastering Functional 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.