functions

def abs = 1
abs + 1
def abs() = 1 
abs() + 1
def abs(x) = x
def abs(x) = { x + 1 }
def +?%&(x) = x //Allowed to have symbols name function
def abs(x: Double):Double = {
    def absHelper() = x
    absHelper()
}

val result = {
    val x = f(3)
    x * x
}

TAIL RECURSION == LOOPS (Reuse stack space)

  • Last action of ft consists of calling another ft

  • ft vs ft * 2

  • @tailrec annonation ensures tail recursive

Anonymous

like javascript

Special Arg Types

CASE match

Partial Application

You can partially apply any argument in the argument list, not just the last one.

Variable Length Args

Representation

Recall Int => Int is a function that takes a Int and returns an Int

Currying

Built in language!

sum takes a function that take ans returns an int and returns a ft that takes two ints and returns an int

Generics

Last updated