Published on

Functional programming in scala

The cheat sheet recaps the course.

List

More functions on lists

lecture 5.1

Pairs and Tuples

lectre 5.2

pairs allows pattern matching:

(x, y) match {
case (Nil, y) => y
case (x, Nil) => x
_ => 
}

Implicit parameters

lecture 5.3

It's a good idea to specify functions arguments in the additional parameters, because the compiler can infer the types of the functions parameters from the regular arguments:

// no necessary to specify w and z types
def function(x:Int, y:Int)(ord: Ordering):Boolean = {
	ord(x,y) < 0
}

Then it is possible to chose an implicit parameter because the compiler is able to infer the kind of implicit function to look up.

// no necessary to specify w and z types
def function(x:Int, y:Int)(implicit ord: Ordering):Boolean = {
	ord(x,y) < 0
}

Higher order functions

lecture 5.4

A high order function takes a other function as argument.

Reduction of lists

lecture 5.5

(x, y)) => x * y
// can be rewritten
_ * _
// however
(x, x)) => x * x
// cannot because each _ represents a new parameter

Reasoning about concat

lecture 5.6

This page was last modified: