Skip to content

Commit

Permalink
Add XorT.toValidatedNel
Browse files Browse the repository at this point in the history
  • Loading branch information
markus1189 committed Jul 13, 2016
1 parent 579e0b4 commit 32438a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/data/XorT.scala
Expand Up @@ -157,6 +157,9 @@ final case class XorT[F[_], A, B](value: F[A Xor B]) {
def toValidated(implicit F: Functor[F]): F[Validated[A, B]] =
F.map(value)(_.toValidated)

def toValidatedNel(implicit F: Functor[F]): F[ValidatedNel[A, B]] =
F.map(value)(_.toValidatedNel)

/** Run this value as a `[[Validated]]` against the function and convert it back to an `[[XorT]]`.
*
* The [[Applicative]] instance for `XorT` "fails fast" - it is often useful to "momentarily" have
Expand Down
6 changes: 6 additions & 0 deletions tests/src/test/scala/cats/tests/XorTTests.scala
Expand Up @@ -113,6 +113,12 @@ class XorTTests extends CatsSuite {
}
}

test("toValidatedNel") {
forAll { (xort: XorT[List, String, Int]) =>
xort.toValidatedNel.map(_.toXor.leftMap(_.head)) should === (xort.value)
}
}

test("withValidated") {
forAll { (xort: XorT[List, String, Int], f: String => Char, g: Int => Double) =>
xort.withValidated(_.bimap(f, g)) should === (xort.bimap(f, g))
Expand Down

0 comments on commit 32438a9

Please sign in to comment.