Functions

This part is about functions as values. A function can be stored, passed and returned; a method that takes one is higher-order; a function that keeps a name from where it was written is a closure. The last three lessons are the tools that follow from those three: partial application, partial functions, tail recursion and a parameter that is evaluated only when the body uses it.

Every program of the part is a whole file with its real output, and each one builds on the lesson before it. The higher-order lesson is the one to read first if the rest of the part is a single idea: the other lessons are that idea at work.

017 Function values a function stored in a val, its type, and Function1 as the type of one argument Open 018 Higher-order functions a method that takes a function, one that returns one, and map, filter and foldLeft Open 019 Closures what a function captures, a counter that stays pure, and the value it closes over Open 020 Partial application and currying the underscore placeholder, a curried method, curried and tupled Open 021 Partial functions isDefinedAt, collect, orElse and lift on a function defined on part of its domain Open 022 Tail recursion @tailrec, the accumulator, and the loop a recursive method compiles to Open 023 By-name parameters a parameter of type => T, when the argument is evaluated, and a helper that short-circuits Open

Lessons