Remix.run Logo
tuetuopay 4 days ago

Depending on your iterator implementation (or, lackthere of), the functional boils down to your first example.

For example, Rust iterators are lazily evaluated with early-exits (when filtering data), thus it's your first form but as optimized as possible. OTOH python's map/filter/etc may very well return a full list each time, like with your intermediate. [EDIT] python returns generators, so it's sane.

I would say that any sane language allowing functional-style data manipulation will have them as fast as manual for-loops. (that's why Rust bugs you with .iter()/.collect())

maleldil 4 days ago | parent | next [-]

Python map/filter/zip/etc. return generators, so they're lazily evaluated.

tuetuopay 3 days ago | parent [-]

Thanks, I was not sure, hence the "may". Comment edited :)

Capricorn2481 4 days ago | parent | prev [-]

Clojure transducers as well.