Skip to content

Instantly share code, notes, and snippets.

@bkyrlach
Created July 14, 2012 13:15
Show Gist options
  • Select an option

  • Save bkyrlach/3111258 to your computer and use it in GitHub Desktop.

Select an option

Save bkyrlach/3111258 to your computer and use it in GitHub Desktop.
Clojure style function...
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