Created
August 21, 2014 23:53
-
-
Save stew/047d3dd9f8371a2b4243 to your computer and use it in GitHub Desktop.
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
import scalaz._ | |
import Scalaz._ | |
object IsItAProfunctor extends App { | |
case class Foo(f: Double) | |
val validateDouble: Double ⇒ Validation[String,Double] = {d ⇒ | |
if(d < 0) "less than zero".fail | |
else d.success | |
} | |
val validateFoo: Foo ⇒ Validation[String,Foo] = validateDouble.dimap((_:Foo).f, _.map(Foo)) | |
assert(validateFoo(Foo(1D)) == Foo(1D).success) | |
assert(validateFoo(Foo(-1D)) == "less than zero".fail) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment