File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ package cats
2+
3+ import simulacrum .typeclass
4+
5+ import cats .data .Xor
6+
7+ /**
8+ * Version of [[cats.FlatMap ]] capable of stack-safe recursive `flatMap`s.
9+ *
10+ * Based on Phil Freeman's
11+ * [[http://functorial.com/stack-safety-for-free/index.pdf Stack Safety for Free ]].
12+ */
13+ @ typeclass trait FlatMapRec [F [_]] extends FlatMap [F ] {
14+
15+ /**
16+ * Keeps calling `f` until a `[[cats.data.Xor.Right Right ]][B]` is returned.
17+ *
18+ * Implementations of this method must use constant stack space.
19+ *
20+ * `f` must use constant stack space. (It is OK to use a constant number of
21+ * `map`s and `flatMap`s inside `f`.)
22+ */
23+ def tailRecM [A , B ](a : A )(f : A => F [A Xor B ]): F [B ]
24+ }
Original file line number Diff line number Diff line change 1+ package cats
2+
3+ import simulacrum .typeclass
4+
5+ @ typeclass trait MonadRec [F [_]] extends Monad [F ] with FlatMapRec [F ]
You can’t perform that action at this time.
0 commit comments