Skip to content

Instantly share code, notes, and snippets.

@Villane
Created July 12, 2011 22:34

Revisions

  1. Villane created this gist Jul 12, 2011.
    12 changes: 12 additions & 0 deletions gistfile1.sbt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    // 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() ]