Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created February 17, 2014 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuwei-k/9046815 to your computer and use it in GitHub Desktop.
Save xuwei-k/9046815 to your computer and use it in GitHub Desktop.
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.0-M5"
object Main1 {
val f = (_: List[Int]).headOption
val g = (_: Int) + 1
val h = (_: Int) + 2
val x: Int => Option[Int] = ???
val y: Int => Option[Int] = ???
def main(args: Array[String]){
val i = f.andThen(_.map(g).map(h))
val z = f.andThen(_.flatMap(x).flatMap(y))
println(i(List(3, 5)))
}
}
object Main2 {
import Main1._
import scalaz._, std.option._
def main(args: Array[String]){
val i = Kleisli(f).map(g).map(h)
val z = Kleisli(f) >==> x >==> y
println(i(List(3, 5)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment