Created
July 14, 2012 13:15
-
-
Save bkyrlach/3111258 to your computer and use it in GitHub Desktop.
Clojure style function...
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
| object Test1 { | |
| val fib: Any => Stream[Int] = { | |
| case () => fib(1) | |
| case (a: Int) => fib(0, a) | |
| case (a: Int, b: Int) => Stream.cons(a, fib(b, a+ b)) | |
| } | |
| val greet: Any => Unit = { | |
| case () => println("Hello, world.") | |
| case (name: String) => println("Hello, " + name + ".") | |
| } | |
| } | |
| class Test2 { | |
| val fib: Any => Stream[Int] = { | |
| case () => fib(1) | |
| case (a: Int) => fib(0, a) | |
| case (a: Int, b: Int) => Stream.cons(a, fib(b, a+ b)) | |
| } | |
| } | |
| object FunctionTest extends App { | |
| println(Test1.fib().take(10).toList) | |
| Test1.greet() | |
| Test1.greet("Bob") | |
| println(new Test2().fib().take(10).toList) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment