June 2018
Intermediate to advanced
316 pages
6h 34m
English
If a function doesn't depend on the state of an object, you should declare it as a first-class citizen. For instance, the main function that we use as the starting point of every program is first-class. To create this function, you need to just declare it in the file as follows:
fun main(vars: Array<String>) {}
All pure functions can be declared in a similar way, for example, the min and max functions:
public inline fun min(a: Int, b: Int): Int = nativeMath.min(a, b)public inline fun max(a: Int, b: Int): Int = nativeMath.max(a, b)
They delegate implementation to functions of a specific platform. In our case, it's java.lang.Math:
import java.lang.Math as nativeMath
But the min and max functions are first-class citizens. ...
Read now
Unlock full access