4 ms·
If you stopped using native loops / forEach how do you handle iteration for the sake of creating side effects? +1 for including take/drop alongside map/reduse/
by przemo_li 9y ago
If you stopped using native loops / forEach how do you handle iteration for the sake of creating side effects?
+1 for including take/drop alongside map/reduse/filter
- splintercell 9y agoIn my experience, there is almost never a need for creating a loop on an array purely for the sake of side effect. For instance, if you want to write something on the log, then loop and collect everything into a single array (using map) and then perform the side effect with a single command (which is a lot more performant in most cases). For asynchronous side effects, create an array of promises using a map, and then run a Promise.all() on that array if you need to resolve all of them. But again, if your experience is different or in your requirements, it is not possible to create a map/reduce/filter transoformation for side effects, then I'd love to hear about it.