The Registers of Rust
This is an excellent, very insightful post.<p>When Erik Meijer worked with Gilad Bracha and others on the Dart team to bring async to Dart, he approached with a very similar "lets look at the table of all the combinations and make sure we didn't leave any holes". In this case, the two axes (effects) he considered were asynchrony and iteration. So Dart supports all four combinations:<p>* Synchronous single-value functions are just normal function declarations. Within one, you use `return` to yield the one value.<p>* Synchronous multi-value functions are generators, marked `sync<i>`, which return a `Iterable<T>`. Within one, you use `yield` and `yield</i>` to emit values.<p>* Asynchronous single-value functions are marked `async` and return a `Future<T>`. Within on, you use `await` to pause on asynchronous operations and consume values. A `return` valued is implicitly wrapped in a future.<p>* Asynchronous multi-value functions are marked `async<i>` and return a `Stream<T>`. Within one, you can use both `yield` and `yield</i>` to emit values and `await` to suspend and consume asynchronous values.<p>We also have an asynchronous `await for` statement that can be used to imperatively consume a stream.<p>There's no third axis for fallibility, because Dart chooses to comprehensively use exceptions for operations that fail (which I quite like).<p>Overall, it's a really rich, comprehensive approach to the problem. I have mixed feelings about it. It really does cover all the bases. But, in practice, `async<i>` functions and `await for` are </i>very* rarely used but add a <i>lot</i> of complexity to the language and engineering burden to the implementations.