Skip to content

Instantly share code, notes, and snippets.

@alexo
Created December 13, 2012 20:59
Show Gist options
  • Save alexo/4279791 to your computer and use it in GitHub Desktop.
Save alexo/4279791 to your computer and use it in GitHub Desktop.
/* Adding ! as a method on int's */
object ExtendBuiltins extends Application {
def fact(n: Int): BigInt =
if (n == 0) 1 else fact(n-1) * n
class Factorizer(n: Int) {
def ! = fact(n)
}
implicit def int2fact(n: Int) = new Factorizer(n)
println("10! = " + (10!))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment