Created
July 12, 2011 22:34
-
-
Save Villane/1079151 to your computer and use it in GitHub Desktop.
Klang: Function Passing
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
// apply the function 'f' twice to the parameter 'n' | |
def twice(n: Int, f: (Int) -> Int) = f(f(n)) | |
// add one to the parameter | |
def addOne(n: Int) = n + 1 | |
// return an initial value and a function | |
def getValueAndFunction(): (Int, myFunc: (Int) -> Int) = (1, addOne) | |
// run twice(...) with the initial value and function from getValueAndFunction() | |
// [] is currently used when passing a tuple directly as function parameters | |
def main() = twice[ getValueAndFunction() ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BTW, ScalaTest is awesome. My tests look like this: