Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import scalaz.syntax.ToIdOps
  2.  
  3. object example extends ToIdOps {
  4. type \/[+A, +B] = scalaz.\/[A, B]
  5. type -\/[+A] = scalaz.-\/[A]
  6. type \/-[+B] = scalaz.\/-[B]
  7. val \/ = scalaz.\/
  8. val -\/ = scalaz.-\/
  9. val \/- = scalaz.\/-
  10. type Either[+A, +B] = \/[A, B]
  11. type Left[+A] = -\/[A]
  12. type Right[+B] = \/-[B]
  13. val Either = \/
  14. object Left {
  15. def unapply[A, B](e: A \/ B): Option[-\/[A]] = Some(e).collect { case l@(-\/(_)) => l }
  16. }
  17. object Right {
  18. def unapply[A, B](e: A \/ B): Option[\/-[B]] = Some(e).collect { case r@(\/-(_)) => r }
  19. }
  20. }
  21.  
  22. import example._
  23.  
  24. val e1: Either[String, Int] = "foo".left
  25. e1 match {
  26. case Left(l) => Some(l)
  27. case Right(r) => None
  28. }
  29. val e2: Either[String, Int] = 2.right
  30. for {
  31. x <- e1
  32. y <- e2
  33. } yield x + y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement