Slice the iterator between the indices. If either index is negative, count from the end. Works similar to Array.prototype.slice.
Array.prototype.slice
For indices 0 ≤ start ≤ end this is the same as calling drop(start) and take(end - start) in sequence on an iterator.
start
end
drop(start)
take(end - start)
import { pipe } from "yta";import { asAsync, range } from "yta/sync";import { slice } from "yta/async";[...pipe(range(15), asAsync(), slice(10))];// => [10, 11, 12, 13, 14][...pipe(range(15), asAsync(), slice(5, 8))];// => [5, 6, 7][...pipe(range(15), slice(-5))];// => [10, 11, 12, 13, 14][...pipe(range(15), slice(0, -5))];// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][...pipe(range(15), slice(5, -5))];// => [5, 6, 7, 8, 9] Copy
import { pipe } from "yta";import { asAsync, range } from "yta/sync";import { slice } from "yta/async";[...pipe(range(15), asAsync(), slice(10))];// => [10, 11, 12, 13, 14][...pipe(range(15), asAsync(), slice(5, 8))];// => [5, 6, 7][...pipe(range(15), slice(-5))];// => [10, 11, 12, 13, 14][...pipe(range(15), slice(0, -5))];// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][...pipe(range(15), slice(5, -5))];// => [5, 6, 7, 8, 9]
Note: Similar to drop and take—because the length of the iterator is not known—if you use negative index the entire iterator has to be consumed before yielding the first item. This can result in an infinite loop if the iterator is indefinite.
See also:
Slice the iterator between the indices. If either index is negative, count from the end. Works similar to
Array.prototype.slice.For indices 0 ≤
start≤endthis is the same as callingdrop(start)andtake(end - start)in sequence on an iterator.Note: Similar to drop and take—because the length of the iterator is not known—if you use negative index the entire iterator has to be consumed before yielding the first item. This can result in an infinite loop if the iterator is indefinite.
See also:
Array.prototype.slice