forked from typelevel/cats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MonadRec instances for Id, Option, OptionT, Either, Xor, XorT, Free, …
…List.
- Loading branch information
1 parent
8a87d55
commit 2617222
Showing
20 changed files
with
304 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cats | ||
package laws | ||
|
||
import cats.data.Xor | ||
import cats.syntax.flatMap._ | ||
import cats.syntax.functor._ | ||
|
||
/** | ||
* Laws that must be obeyed by any `FlatMapRec`. | ||
*/ | ||
trait FlatMapRecLaws[F[_]] extends FlatMapLaws[F] { | ||
implicit override def F: FlatMapRec[F] | ||
|
||
def tailRecMConsistentFlatMap[A](a: A, f: A => F[A]): IsEq[F[A]] = { | ||
val bounce = F.tailRecM[(A, Int), A]((a, 1)) { case (a0, i) => | ||
if(i > 0) f(a0).map(a1 => Xor.left((a1, i-1))) | ||
else f(a0).map(Xor.right) | ||
} | ||
bounce <-> f(a).flatMap(f) | ||
} | ||
} | ||
|
||
object FlatMapRecLaws { | ||
def apply[F[_]](implicit ev: FlatMapRec[F]): FlatMapRecLaws[F] = | ||
new FlatMapRecLaws[F] { def F: FlatMapRec[F] = ev } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cats | ||
package laws | ||
|
||
/** | ||
* Laws that must be obeyed by any `MonadRec`. | ||
*/ | ||
trait MonadRecLaws[F[_]] extends MonadLaws[F] with FlatMapRecLaws[F] { | ||
implicit override def F: MonadRec[F] | ||
} | ||
|
||
object MonadRecLaws { | ||
def apply[F[_]](implicit ev: MonadRec[F]): MonadRecLaws[F] = | ||
new MonadRecLaws[F] { def F: MonadRec[F] = ev } | ||
} |
Oops, something went wrong.