- WASM multi-values allows for nicely efficient and ergonomic iterator protocols. My language defines iterators with a multi-return next(): interface Iterator<T> { next(): (true, T) | (false, never); } - One method, not two like next/value designs - No heap allocations!Feb 4, 2026 20:04
- (X, Y, ...) is an unboxed tuple. They can't be stored in references, only destructured. Works great with pattern matching: match iter.next() { case (true, value) => process(value), // value: T case (false, _) => done(), // _ is never, can't be bound }
- And while/let and if/let: while (let (true, item) = iter.next()) { // Only matches when first element is true // item is T, not T | never } And for/in loops keep the implicit hasMore value on the stack like in the two method design.