Tutorial by Examples

Anonymous functions are functions that are defined but not assigned a name. The following is an anonymous function that takes in two integers and returns the sum. (x: Int, y: Int) => x + y The resultant expression can be assigned to a val: val sum = (x: Int, y: Int) => x + y Anonymous...
Function composition allows for two functions to operate and be viewed as a single function. Expressed in mathematical terms, given a function f(x) and a function g(x), the function h(x) = f(g(x)). When a function is compiled, it is compiled to a type related to Function1. Scala provides two method...
trait PartialFunction[-A, +B] extends (A => B) Every single-argument PartialFunction is also a Function1. This is counter-intuitive in a formal mathematical sense, but better fits object oriented design. For this reason Function1 does not have to provide a constant true isDefinedAt method. To...

Page 1 of 1