Skip to content

Commit

Permalink
Merge pull request #1188 from markus1189/xort-tovalidatednel
Browse files Browse the repository at this point in the history
Add XorT.toValidatedNel
  • Loading branch information
peterneyens authored Jul 13, 2016
2 parents fe361a3 + 32438a9 commit acd5892
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 acd5892

Please sign in to comment.