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))