DEV Community

Discussion on: PromiseExtra.sequence

Collapse
 
aminnairi profile image
Amin • Edited

Hi @lukeshiru and thank you for your kind comment!.

I knew someone was gonna post a solution using recursion. I really love your solution (since I'm a functional programming amateur) which is shorter and simpler to understand (at least from my point of view) than mine using Array.prototype.reduce.

Actually, I would have used recursion in JavaScript all the way if proper tail call (and/or tail call optimizations) was a thing, and not only on Safari but in any platform. Since it is part of the ES2015 standard, I hope that it is and that someday it becomes a thing (even though Google Chrome seemed not pleased about it and has shown signs that they won't support PTC & TCO anytime soon).

But I guess it is okay to use it since we won't hit the call stack size limit anytime soon with this niche use-case.

And since you offered some variations of this sequence method, it makes me believe that there are so much more static methods that could be added to the Promise object for things like filtering, mapping, reducing, sequencing, accumulating etc... This may be a good candidate for a library some day.

Anyway, thanks again for your interest in this article. I'll see you soon and have a wonderful new year's eve.