-
Notifications
You must be signed in to change notification settings - Fork 34
Combine nested iterators (a sort of flatMap) #45
Comments
This is essentially a Cartesian product. If the proposal includes a range(1, 10)
.flatMap(a => range(a+1, 10)
.flatMap(b => range(b+1, 10)
.map(c => [a, b, c])
)
); |
Now that the proposal has been simplified I wouldn't be totally against adding a flatMap /cc @domenic |
@michaelficarra expressed interest in |
Does this look good?
|
@devsnek To match |
What should it flatten? Only iterators? What about iterables? Related tc39/proposal-collection-methods#34 |
It should probably flatten iterables, mapping over random values should use the outermost protocol. |
The answer to that depends somewhat on whether there might ever be a |
Only iterators. " |
@michaelficarra |
I'd prefer to use Symbol.iterator as the indicator, which should be fine as this proposal also encourages all iterators to be iterable as well. |
Those 2 expressions give the same result, but only the first one can iterate lazily
Would it possible, with this proposal, or with an additional iterator method, to combine those 3
range()
iterators lazily and behave liketripleSorted
?Edit: some code achieving the same result lazily
the idea is to be able to express something equivalent to python's list comprehensions (even if it's not necessarily lazy in that case):
The text was updated successfully, but these errors were encountered: