Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upconcatAll and concatMap rather than flatten and flatMap #60
Comments
This comment has been minimized.
This comment has been minimized.
The issue with the name “concat” is that it comes along with Array concat’s IsConcatSpreadable behavior, which i don’t think anyone wants to see spread elsewhere. |
This comment has been minimized.
This comment has been minimized.
@ljharb it doesn't seem to be that big of an issue though. Most people don't even know that exists. And concat is a nice, specific, well-understood name. |
This comment has been minimized.
This comment has been minimized.
This is the most sensible solution that I have seen. Really like that it builds on the already existing concat method, should help with education. [ [‘a’], [‘b’], [‘c’] ].concatAll()
===
[‘a’].concat([‘b’]).concat([‘c’]) Does what it says on the tin |
This comment has been minimized.
This comment has been minimized.
@acutmore that's the problem tho; it wouldn't work the same for NodeLists. |
This comment has been minimized.
This comment has been minimized.
This is a neat idea, but I'd worry a lot about the difference between |
This comment has been minimized.
This comment has been minimized.
Which are DOM APIs that select items, this is a JavaScript API that transforms an array. I'm not convinced that querySelectorAll is at all relevant.
Why not make it work the same for NodeLists, et al? Why can't this also account for |
This comment has been minimized.
This comment has been minimized.
The committee consensus was that this proposal could not proceed unless it did not care about IsConcatSpreadable, which is why it was changed to checking IsArray. Any part of the name “concat” is imo not an option. |
This comment has been minimized.
This comment has been minimized.
Context? It seems unreasonable given that what this method actually does is concatenate things, where |
This comment has been minimized.
This comment has been minimized.
The PR is #38. As for “little used”, standards can’t ignore any edge case, no matter how small - that’s why that symbol exists in the first place. |
This comment has been minimized.
This comment has been minimized.
Why does it have to be based on While Most of the functional community (people who use these operations on MANY types) have settled on the FL spec. Also there is no conflict to be reconciled by using So I propose do what you think is needed to alleviate the naming Just my 2 cents. EDIT: This is more an argument against using |
This comment has been minimized.
This comment has been minimized.
Actually after all that it looks like there is no EDIT: Also as |
This comment has been minimized.
This comment has been minimized.
@ljharb Please could you explain why IsConcatSpreadable would cause an issue? I have only just come across that Symbol so not aware of the reasons why it should be avoided. I can see how adding that extra check will reduce performance but does give people a way to opt-in to flattening array-like objects. |
This comment has been minimized.
This comment has been minimized.
TC39 reps blocked this proposal as long as it had that check; I’ll let them speak up here if they wish to explain their reasons, but that is nonetheless the situation. |
TL;DR: Try
concatAll
andconcatMap
because they're more specific to the actual behavior thanflatten
andflatMap
, because "flat" has a more general meaning. Also, there's popular precedent in RxRxJS has a precedent here, as
concatMap
andconcatAll
do the same thing in RxJS as what is proposed here, whereflatMap
(which changed tomergeMap
in v5 because it's too ambiguous as to how it's "flattening") does something very different and very specific to observing pushed values.Specifically this is the behavior of
concatMap
andconcatAll
in RxJS:concatMap: (roughly speaking) maps to a new observables, and plays them in a serial fashion, one at a time, end to end.
concatAll: Takes a higher-order Observable (Observable<Observable>), and queues up each inner observable, playing them in a serial fashion, one at a time, end to end.
As you can see,
concatMap
is more likeArray.prototype.flatMap
(proposed) than RxJS'sflatMap
is. "flat" doesn't makes as much sense in Observable-land because there is more than two dimensions to deal choose to flatten, there's also time. With an array, there, could only be two dimensions, the length of the array, and the depth. Because of that ambiguity, RxJS opted to go with something more specific and moved away fromflatMap
and named itmergeMap
(which as you can see above is very different from theflatMap
proposed here).It's just a proposal as an alternative to "smoosh".
I feel like I've rambled, but I hope that gets the idea across.