Functions and objects
Closures, methods and interfaces. ChatGPT said we were missing them, so here they are.
Closures
Parameter and return types are inferred from where the closure goes, or written out: |a: Int, b: Int| -> Int { a + b }. Function types look like fn(String) -> Bool, named functions are values too (xs.map(double)), and arrays have map, filter, fold, each, any, all, find and sort_by.
Closures capture copies of what they use, component state included: a view that filters with a closure updates when the state it captured changes.
They cannot assign to captured variables or state; return the new value instead. return inside a closure returns from the closure.
A struct field or component property can hold a function: Tag(n: n, format: |x| "#{x}"), and button.on_press() calls it.
Methods
Interfaces
A value turns into an interface it implements wherever the interface is expected: arguments, annotated lets, array elements, struct fields, return values. A missing or mistyped method is a compile error that spells out the signature you owe.