Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XorT.toValidatedNel #1188

Merged
merged 1 commit into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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