Skip to content

Instantly share code, notes, and snippets.

@leedm777
Created September 13, 2012 19:36
Show Gist options
  • Save leedm777/3717022 to your computer and use it in GitHub Desktop.
Save leedm777/3717022 to your computer and use it in GitHub Desktop.
Object can be functions in Scala
scala> object ImaFunction {
| def apply() { println("I am a function") }
| }
defined module ImaFunction
scala> case class Sois(name: String) {
| def apply() { printf("%s is also a function", name) }
| }
defined class Sois
scala> ImaFunction()
I am a function
scala> val x = Sois("x")
x: Sois = Sois(x)
scala> x()
x is also a function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment