Skip to content

Instantly share code, notes, and snippets.

@stew
Created August 21, 2014 23:53
Show Gist options
  • Save stew/047d3dd9f8371a2b4243 to your computer and use it in GitHub Desktop.
Save stew/047d3dd9f8371a2b4243 to your computer and use it in GitHub Desktop.
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