-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1155 from peterneyens/creating-xort-from-xor-or-fa
Add syntax to create a XorT from an F[A] and from a Xor.
- Loading branch information
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cats | ||
package syntax | ||
|
||
import cats.data.XorT | ||
|
||
trait XorTSyntax extends XorTSyntax1 { | ||
implicit def catsSyntaxXorT[F[_]: Functor, A](fa: F[A]): XorTFunctorOps[F, A] = new XorTFunctorOps(fa) | ||
} | ||
|
||
private[syntax] trait XorTSyntax1 { | ||
implicit def catsSyntaxUXorT[FA](fa: FA)(implicit U: Unapply[Functor, FA]): XorTFunctorOps[U.M, U.A] = | ||
new XorTFunctorOps[U.M, U.A](U.subst(fa))(U.TC) | ||
} | ||
|
||
final class XorTFunctorOps[F[_]: Functor, A](val fa: F[A]) { | ||
/** | ||
* Lift this `F[A]` into a `XorT[F, A, R]`. | ||
* | ||
* {{{ | ||
* scala> import cats.implicits._ | ||
* scala> val oa: Option[String] = Some("boo") | ||
* scala> oa.leftXorT[Int] | ||
* res0: cats.data.XorT[Option,String,Int] = XorT(Some(Left(boo))) | ||
* }}} | ||
*/ | ||
def leftXorT[R]: XorT[F, A, R] = XorT.left(fa) | ||
|
||
/** | ||
* Lift this `F[A]` into a `XorT[F, L, A]`. | ||
* | ||
* {{{ | ||
* scala> import cats.implicits._ | ||
* scala> val oa: Option[Int] = Some(1) | ||
* scala> oa.rightXorT[String] | ||
* res0: cats.data.XorT[Option,String,Int] = XorT(Some(Right(1))) | ||
* }}} | ||
*/ | ||
def rightXorT[L]: XorT[F, L, A] = XorT.right(fa) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters