Iterables Background
Iterables Background
@lou.codes/iterables
is a collection of curried utils to work with iterables
in a functional fashion without having to use for
, while
and so on directly.
Why
I always liked the curried approach of stuff like map
in which you generate a
mapping function first:
And then you can use it to map any array:
When I discovered how powerful that style was, I wanted to use it all over. Now the โlimitationโ of those types of functions is that they first run the mapping function on every item, before going to the next. Iterators on the other side run all functions on each item, which in some scenarios can be more efficient.
This from my point of view is great, so I wanted to have a library that would allow me to use this style of programming with iterators, and thatโs how this library was born.
How
I built this library using TypeScript, with configurations from my shared configs. I made it ESM only as soon as Node started supporting ESM modules, and I made it tree-shakeable by using named exports.
Over the development of this library I found some challenges like making the result of iterators iterable again, so we can map multiple times from the same iterator.
I went back and forward with the idea of making utils handle async
automatically, but the cost in size and performance made me decide to split the
utils into @lou.codes/iterables
and @lou.codes/iterables/asynchronous
.
Where
This library proved to be really useful for me, so I used it for others like cron, notify and window-open-promise.
Iโve also used it in some private projects, with great results.