You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Double-ended iterators could support takeLast/dropLast methods. The result iterator of drop/dropLast could still be double-ended, because drop/dropLast just skip some items. But take/takeLast are different. Normally, the result of take() can only call next(), similarly, the result of takeLast() can only call nextLast(). So deiter.takeLast(1000).filter(x => x > 0).take(10) won't work (throw TypeError). deiter.takeLast(1000).filter(x => x > 0).toArray().values().take(10) could work, but require convert to array is inconvenient, and waste memory (in the example, we only need 10 items, but we create an 1000 items array).
Consider take/drop/takeLast/dropLast normally only have a relative small n, a better solution is using buffer based semantic like tc39/proposal-iterator-helpers#81 (comment) , so invoking all these four methods on deiters always return deiters.
The text was updated successfully, but these errors were encountered:
One problem is how the biggest limit we support ? Consider the largest array length is 2**32-1, it seems this should be the max, or could it be even a small number, like 10000? If larger than the max, just throw? or some other behavior?
A special case is limit == Infinity, in that case, take/takeLast should return a simple wrapper, no need to buffer, always deiter.
Double-ended iterators could support
takeLast/dropLast
methods. The result iterator ofdrop/dropLast
could still be double-ended, becausedrop/dropLast
just skip some items. Buttake/takeLast
are different. Normally, the result oftake()
can only callnext()
, similarly, the result oftakeLast()
can only callnextLast()
. Sodeiter.takeLast(1000).filter(x => x > 0).take(10)
won't work (throw TypeError).deiter.takeLast(1000).filter(x => x > 0).toArray().values().take(10)
could work, but require convert to array is inconvenient, and waste memory (in the example, we only need 10 items, but we create an 1000 items array).Consider
take/drop/takeLast/dropLast
normally only have a relative smalln
, a better solution is using buffer based semantic like tc39/proposal-iterator-helpers#81 (comment) , so invoking all these four methods on deiters always return deiters.The text was updated successfully, but these errors were encountered: