Scala - Function

Syntax

def functionName ([list of parameters]) : [return type]

Signature

High Order

Higher order functions are functions that take a function as a parameter or return functions.

Evaluation

  • Call by value: evaluates the function arguments before calling the function
  • Call by name: evaluates the function first, and then evaluates the arguments if needed
def square(x: Double)    // call by value
def square(x: => Double) // call by name
def myFct(bindings: Int*) = { ... } // bindings is a sequence of int, containing a varying # of arguments

Powered by ComboStrap