Created
July 15, 2013 20:02
-
-
Save non/6002945 to your computer and use it in GitHub Desktop.
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 characters
| 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