Skip to content

Commit

Permalink
Improve the type signature of orElse
Browse files Browse the repository at this point in the history
The whole point of orElse is to drop the left hand value of a Disjunction, no sense having the type that is dropped influence the resulting type.
  • Loading branch information
jedesah committed Oct 16, 2015
1 parent 87c3fb3 commit 798d4c1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 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,8 @@ 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 =
fold(_ => fallback, a => Xor.Right(a))

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 798d4c1

Please sign in to comment.