Skip to content

Commit

Permalink
Merge pull request #575 from jedesah/topic/improve_signature_orElse_o…
Browse files Browse the repository at this point in the history
…f_Xor

Improve the type signature of orElse
  • Loading branch information
stew committed Oct 16, 2015
2 parents 87c3fb3 + 68e4e49 commit 42baab7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/src/main/scala/cats/data/Xor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ sealed abstract class Xor[+A, +B] extends Product with Serializable {

def getOrElse[BB >: B](default: => BB): BB = fold(_ => default, identity)

def orElse[AA >: A, BB >: B](fallback: => AA Xor BB): AA Xor BB =
fold(_ => fallback, _ => this)
def orElse[C, BB >: B](fallback: => C Xor BB): C Xor BB = this match {
case Xor.Left(_) => fallback
case r @ Xor.Right(_) => r
}

def recover[BB >: B](pf: PartialFunction[A, BB]): A Xor BB = this match {
case Xor.Left(a) if pf.isDefinedAt(a) => Xor.right(pf(a))
Expand Down

0 comments on commit 42baab7

Please sign in to comment.