Skip to content

Commit

Permalink
Merge pull request #807 from notxcain/xort-valueor
Browse files Browse the repository at this point in the history
Add XorT#valueOr
  • Loading branch information
ceedubs committed Jan 15, 2016
2 parents 0c0379e + 07d0cd1 commit 35e376b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/scala/cats/data/XorT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ final case class XorT[F[_], A, B](value: F[A Xor B]) {
}
})

def valueOr[BB >: B](f: A => BB)(implicit F: Functor[F]): F[BB] = fold(f, identity)

def forall(f: B => Boolean)(implicit F: Functor[F]): F[Boolean] = F.map(value)(_.forall(f))

def exists(f: B => Boolean)(implicit F: Functor[F]): F[Boolean] = F.map(value)(_.exists(f))
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 @@ -153,6 +153,12 @@ class XorTTests extends CatsSuite {
}
}

test("valueOr with Id consistent with Xor valueOr") {
forAll { (xort: XorT[Id, String, Int], f: String => Int) =>
xort.valueOr(f) should === (xort.value.valueOr(f))
}
}

test("getOrElse with Id consistent with Xor getOrElse") {
forAll { (xort: XorT[Id, String, Int], i: Int) =>
xort.getOrElse(i) should === (xort.value.getOrElse(i))
Expand Down

0 comments on commit 35e376b

Please sign in to comment.