2 ms·
> If you have an intermediate collection, it's in memory somewhere, even if the language does the allocation for you transparently. This toy example algorithm,
by exDM69 13y ago
> If you have an intermediate collection, it's in memory somewhere, even if the language does the allocation for you transparently.
This toy example algorithm, and many practical algorithms, do not need an intermediate collection to be stored in memory.
Using some kind of laziness, you only need exactly one temporary element, not the whole collection. You can make this happen not only in Haskell but also using Python generators, Clojure lazy sequences or even in C++ using Folly.
The lack of means of composition, the inability to pipe the output of one algorithm as the input of another, is in my opinion the greatest shortcoming of C++ <algorithm>.