3 ms·
> Say we make a Future<Int> and then chain `.map(|x| x+1)` on a dynamic number of times (N). Each time you call `.map` it statically produces a different type,
by pcwalton 10y ago
> Say we make a Future<Int> and then chain `.map(|x| x+1)` on a dynamic number of times (N).
Each time you call `.map` it statically produces a different type, similar to how iterators work. So you can't actually do that—unless you box the trait, producing an allocation chain.
Of course, in the real world you'd probably not write it that way, and you'd maintain a counter and do the add in one go, which results in a static state machine.