Created
December 13, 2012 20:59
-
-
Save alexo/4279791 to your computer and use it in GitHub Desktop.
This file contains 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
/* 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