Skip to content

Instantly share code, notes, and snippets.

@non
Created July 15, 2013 20:02
Show Gist options
  • Select an option

  • Save non/6002945 to your computer and use it in GitHub Desktop.

Select an option

Save non/6002945 to your computer and use it in GitHub Desktop.
d_m@vein ~ $ scala
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val f0 = () => 999
f0: () => Int = <function0>
scala> val f1 = (n: Int) => n + 123
f1: Int => Int = <function1>
scala> implicit class Blah[A, B](f: Function1[A, B]) { def compose0(g: Function0[A]) = () => f(g()) }
defined class Blah
scala> f1.compose0(f0)
res0: () => Int = <function0>
scala> f1.compose0(f0)()
res1: Int = 1122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment