Skip to content

Commit

Permalink
Merge pull request #971 from liff/topic/xor-toValidatedNel
Browse files Browse the repository at this point in the history
Add toValidatedNel to Xor
  • Loading branch information
adelbertc committed Apr 6, 2016
2 parents 59a7844 + 8a18a73 commit b3033e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
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

0 comments on commit b3033e2

Please sign in to comment.