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.
Merge pull request typelevel#1289 from adelbertc/stdlib-eithert
Replace Xor with Either, fixes typelevel#1192
- Loading branch information
Showing
75 changed files
with
1,698 additions
and
412 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,45 @@ | ||
package cats | ||
package arrow | ||
|
||
import cats.data.Xor | ||
|
||
import simulacrum.typeclass | ||
|
||
@typeclass trait Choice[F[_, _]] extends Category[F] { | ||
|
||
/** | ||
* Given two `F`s (`f` and `g`) with a common target type, create a new `F` | ||
* with the same target type, but with a source type of either `f`'s source | ||
* type OR `g`'s source type. | ||
* | ||
* Example: | ||
* {{{ | ||
* scala> import cats.data.Xor | ||
* scala> import cats.implicits._ | ||
* scala> val b: Boolean => String = _ + " is a boolean" | ||
* scala> val i: Int => String = _ + " is an integer" | ||
* scala> val f: (Boolean Xor Int) => String = Choice[Function1].choice(b, i) | ||
* scala> val f: (Either[Boolean, Int]) => String = Choice[Function1].choice(b, i) | ||
* | ||
* scala> f(Xor.right(3)) | ||
* scala> f(Right(3)) | ||
* res0: String = 3 is an integer | ||
* | ||
* scala> f(Xor.left(false)) | ||
* scala> f(Left(false)) | ||
* res0: String = false is a boolean | ||
* }}} | ||
*/ | ||
def choice[A, B, C](f: F[A, C], g: F[B, C]): F[Xor[A, B], C] | ||
def choice[A, B, C](f: F[A, C], g: F[B, C]): F[Either[A, B], C] | ||
|
||
/** | ||
* An `F` that, given a source `A` on either the right or left side, will | ||
* return that same `A` object. | ||
* | ||
* Example: | ||
* {{{ | ||
* scala> import cats.data.Xor | ||
* scala> import cats.implicits._ | ||
* scala> val f: (Int Xor Int) => Int = Choice[Function1].codiagonal[Int] | ||
* scala> val f: (Either[Int, Int]) => Int = Choice[Function1].codiagonal[Int] | ||
* | ||
* scala> f(Xor.right(3)) | ||
* scala> f(Right(3)) | ||
* res0: Int = 3 | ||
* | ||
* scala> f(Xor.left(3)) | ||
* scala> f(Left(3)) | ||
* res1: Int = 3 | ||
* }}} | ||
*/ | ||
def codiagonal[A]: F[Xor[A, A], A] = choice(id, id) | ||
def codiagonal[A]: F[Either[A, A], A] = choice(id, id) | ||
} |
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
Oops, something went wrong.