Skip to content

Commit

Permalink
Add convenience wrapper for Xor.fromOption in XorT.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkotsbakws committed Jun 1, 2016
1 parent 2fb4d1d commit 43fb68f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/main/scala/cats/data/XorT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ trait XorTFunctions {
def apply[E, A](eit: Either[E,A])(implicit F: Applicative[F]): XorT[F, E, A] =
XorT(F.pure(Xor.fromEither(eit)))
}

final def fromOption[F[_]]: FromOptionPartiallyApplied[F] = new FromOptionPartiallyApplied

final class FromOptionPartiallyApplied[F[_]] private[XorTFunctions] {
def apply[E, A](opt: Option[A], ifNone: => E)(implicit F: Applicative[F]): XorT[F, E, A] =
fromXor[F](Xor.fromOption(opt, ifNone))
}
}

private[data] abstract class XorTInstances extends XorTInstances1 {
Expand Down

0 comments on commit 43fb68f

Please sign in to comment.