Idea: cheap trivial streams / futures
(post-0.3.0)
Currently we use option<stream<...>> (e.g. here) to avoid stream bookkeeping for empty streams (iirc).
As an alternative, how about a stream.empty built-in that returns a "pre-dropped" readable stream? This would be semantically equivalent to stream.new + stream.drop-writable.
A little more complicated but potentially even more useful would be a future.resolved, acting like future.new + future.write. There are a lot of future<result<...>> return types that could benefit from being able to return future.resolved(err(...)).
Good ideas and thanks for filing! I've also wondered about the same thing. If we can find real workloads where it's a speedup to have these sorts of "fused" built-ins, I think it'd make sense to add them.
I guess I'm seeing option<stream<...>> as evidence that someone at least thinks that its worth avoiding an extra stream allocation. 🙂
Assuming there's no semantic distinction between none and an empty stream, I suppose there's also an ergonomic advantage with option<stream<...>> since, depending on the bindings, it's easier to pass nothing than to figure out how to conjure an empty stream.