From 32438a977357c7996a5431417b6a898f2560dd3f Mon Sep 17 00:00:00 2001 From: Markus Hauck Date: Wed, 13 Jul 2016 08:48:21 +0200 Subject: [PATCH] Add XorT.toValidatedNel --- core/src/main/scala/cats/data/XorT.scala | 3 +++ tests/src/test/scala/cats/tests/XorTTests.scala | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/core/src/main/scala/cats/data/XorT.scala b/core/src/main/scala/cats/data/XorT.scala index 74ef40bd9b..4ec93aa120 100644 --- a/core/src/main/scala/cats/data/XorT.scala +++ b/core/src/main/scala/cats/data/XorT.scala @@ -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 diff --git a/tests/src/test/scala/cats/tests/XorTTests.scala b/tests/src/test/scala/cats/tests/XorTTests.scala index 6e787b240f..52d86570b7 100644 --- a/tests/src/test/scala/cats/tests/XorTTests.scala +++ b/tests/src/test/scala/cats/tests/XorTTests.scala @@ -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))