Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scalaz.syntax.ToIdOps
- object example extends ToIdOps {
- type \/[+A, +B] = scalaz.\/[A, B]
- type -\/[+A] = scalaz.-\/[A]
- type \/-[+B] = scalaz.\/-[B]
- val \/ = scalaz.\/
- val -\/ = scalaz.-\/
- val \/- = scalaz.\/-
- type Either[+A, +B] = \/[A, B]
- type Left[+A] = -\/[A]
- type Right[+B] = \/-[B]
- val Either = \/
- object Left {
- def unapply[A, B](e: A \/ B): Option[-\/[A]] = Some(e).collect { case l@(-\/(_)) => l }
- }
- object Right {
- def unapply[A, B](e: A \/ B): Option[\/-[B]] = Some(e).collect { case r@(\/-(_)) => r }
- }
- }
- import example._
- val e1: Either[String, Int] = "foo".left
- e1 match {
- case Left(l) => Some(l)
- case Right(r) => None
- }
- val e2: Either[String, Int] = 2.right
- for {
- x <- e1
- y <- e2
- } yield x + y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement