Created
December 23, 2015 12:07
Revisions
-
eamelink revised this gist
Dec 23, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,6 @@ object Test extends App{ age <- 15.right[FailType] if age >= 18 } yield age println(result) // Prints -\/(FailType(too bad buddy!)) } -
eamelink created this gist
Dec 23, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import scalaz._ import scalaz.Scalaz._ object Test extends App{ trait Zero[A] { def zero: A } implicit class RichDisjunction[A, B](value: A \/ B) { def withFilter(p: B => Boolean)(implicit za: Zero[A]): A \/ B = value match { case \/-(b) if !p(b) => -\/(za.zero) case _ => value } } case class FailType(msg: String) implicit val zeroFailType = new Zero[FailType] { val zero = FailType("too bad buddy!") } val result = for { age <- 15.right[FailType] if age >= 18 } yield age println(result) }