4 ms·
I think `Array.map` is a perfectly reasonable reading of "you're iterating over some structure and collecting your results in a sequence". But sure, in the `fo
by deredede 2y ago
I think `Array.map` is a perfectly reasonable reading of "you're iterating over some structure and collecting your results in a sequence".
But sure, in the `fold` scenario where you don't know the number of results in advance (you are more likely to know if you use imperative data structures, e.g. `Hashtbl.length` is constant-time whereas `Map.cardinal` is not), lists might be faster than growing arrays with copies. They are still going to use more memory, and they are unlikely to to be faster than a rope-like structure that grows with no copies.
- senorrib 2y agoIt isn’t. There’s no guarantee that .map will be processed in sequence. In fact, .map is usually a great candidate for parallelization.
- deredede 2y agoThe "sequence" in the problem statement does not refer to the order of operations but to the data structure storing the results. A parallel `Array.map` still computes a sequence, even though it may not compute in sequence.