SplitScript reference / Language / fn

fn

declaration

fn name(parameters) { ... }

Declares a function or method.

Each parameter may be an irrefutable binding pattern. It still consumes exactly one argument; an annotation applies to that complete argument while the projected names receive their field or payload types. Parameter and result annotations are optional when constraints from the body and call sites determine them. A function declared -> iterator T may either forward an existing iterator with ordinary return or become a lazy synchronous generator by using yield.

Examples

Declare a helper

fn isBoss(level) {
    return level == 7
}