Skip to content
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

Add toValidatedNel to Xor #971

Merged
merged 1 commit into from
Apr 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/scala/cats/data/Xor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ sealed abstract class Xor[+A, +B] extends Product with Serializable {

def toValidated: Validated[A,B] = fold(Validated.Invalid.apply, Validated.Valid.apply)

/** Returns a [[ValidatedNel]] representation of this disjunction with the `Left` value
* as a single element on the `Invalid` side of the [[NonEmptyList]]. */
def toValidatedNel[AA >: A]: ValidatedNel[AA,B] = fold(Validated.invalidNel, Validated.valid)

def withValidated[AA,BB](f: Validated[A,B] => Validated[AA,BB]): AA Xor BB =
f(toValidated).toXor

Expand Down
1 change: 1 addition & 0 deletions tests/src/test/scala/cats/tests/XorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class XorTests extends CatsSuite {
x.isLeft should === (x.toOption.isEmpty)
x.isLeft should === (x.toList.isEmpty)
x.isLeft should === (x.toValidated.isInvalid)
x.isLeft should === (x.toValidatedNel.isInvalid)
}
}

Expand Down