method
List.sort_by
List.sort_by(s, key) -> void
Sorts s in place, ascending, by the number each element maps to through key — a function taking one element and returning an int, fixed, or long. This is how you sort records and entities rather than bare scalars: draw order by y, an inventory by price, nearest targets by distance. The sort is stable (O(n log n) merge sort), so elements with equal keys keep the order they already had — the tie-break that keeps sprites from flickering when their y matches.
Example
# doc-check: skip — illustrative; `key` is any fn(element) -> number in scope
function draw_key(e: Sprite) -> int { return e.y }
program Demo {
handler Step phase Update {
List.sort_by(sprites, draw_key) # back-to-front draw order
}
}