Open homam opened 8 years ago
I'm increasingly worried about "because it saves an extra loop" as a reason to add a new utility function. Should we also have fold-obj-to-list-then-filter
because it saves an extra filter
? Arbitrary amounts of loop fusion could be done this way (and many like concat-map
and partition
already exist), but as you demonstrate, they are logically redundant with existing operations.
That said, I've often wanted to fold an object into a list. Consider this a slightly reluctant +1.
Your comment's code blocks call it fold-obj-to-pairs
. Those should be fold-obj-to-list
right?
(group-by f) >> obj-to-pairs >> (map ([k, v]) -> merge k, v)
is a very common pattern when dealing with tabular data like the result of SQL queries. I wish LiveScript had a compiler that supported fusion but ...
I think there's a need for an abstract obj-to-pairs
: obj-to-pairs = fold-obj-to-list (a, b) -> [a, b]
fold-obj-to-list
can save an extramap
:It's defined like: