-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Xor with Either, fixes #1192 #1289
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3bc775f
Prefer Either over Xor, fixes #1192
adelbertc 21bab6b
Merge remote-tracking branch 'upstream/master' into stdlib-eithert
adelbertc a43527f
Add Either(T) tests and replace Xor with Either in tests
adelbertc 8fc564e
ScalaStyle fixes
adelbertc 4530d3a
Fix ScalaDoc, address comments
adelbertc d4df094
Eval uses defaultTailRecM
adelbertc eedd057
Safer Either casting
adelbertc ba1a786
Expose Left/Right cast syntax - casting naming indicates which type p…
adelbertc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change this to
defaultTailRecM(a)(f)
?