Variable: sliceAsync()
const
sliceAsync: {<Start
>(start
): {<End
>(End
): <Value
>(asyncIterable
) =>AsyncIterable
<Value
>; <End
,Value
>(End
,asyncIterable
):AsyncIterable
<Value
>; }; <Start
,End
>(start
,End
): <Value
>(asyncIterable
) =>AsyncIterable
<Value
>; <Start
,End
,Value
>(start
,End
,asyncIterable
):AsyncIterable
<Value
>; }
Defined in: splices.d.ts:637
Returns an async iterable containing the values of asyncIterable
between
start
and end
(exclusive) of asyncIterable
.
If any part of the range between start
and end
is outside the bounds of
the async iterable, then that part is excluded from the returned async
iterable. Thus, the returned async iterable may be empty.
WARNING: This function linearly iterates up to end
because async iterables
do not support random access.
Call Signature
<
Start
>(start
): {<End
>(End
): <Value
>(asyncIterable
) =>AsyncIterable
<Value
>; <End
,Value
>(End
,asyncIterable
):AsyncIterable
<Value
>; }
Type Parameters
Start
Start
extends number
Parameters
start
NonNegativeInteger
<Start
>
Returns
<
End
>(End
): <Value
>(asyncIterable
) =>AsyncIterable
<Value
>
Type Parameters
End
End
extends number
Parameters
End
NonNegativeInteger
<End
>
Returns
<
Value
>(asyncIterable
):AsyncIterable
<Value
>
Type Parameters
Value
Value
Parameters
asyncIterable
AsyncIterable
<Value
>
Returns
AsyncIterable
<Value
>
<
End
,Value
>(End
,asyncIterable
):AsyncIterable
<Value
>
Type Parameters
End
End
extends number
Value
Value
Parameters
End
NonNegativeInteger
<End
>
asyncIterable
AsyncIterable
<Value
>
Returns
AsyncIterable
<Value
>
Call Signature
<
Start
,End
>(start
,End
): <Value
>(asyncIterable
) =>AsyncIterable
<Value
>
Type Parameters
Start
Start
extends number
End
End
extends number
Parameters
start
NonNegativeInteger
<Start
>
End
NonNegativeInteger
<End
>
Returns
<
Value
>(asyncIterable
):AsyncIterable
<Value
>
Type Parameters
Value
Value
Parameters
asyncIterable
AsyncIterable
<Value
>
Returns
AsyncIterable
<Value
>
Call Signature
<
Start
,End
,Value
>(start
,End
,asyncIterable
):AsyncIterable
<Value
>
Type Parameters
Start
Start
extends number
End
End
extends number
Value
Value
Parameters
start
NonNegativeInteger
<Start
>
End
NonNegativeInteger
<End
>
asyncIterable
AsyncIterable
<Value
>
Returns
AsyncIterable
<Value
>
Throws
if either start
or end
is not a non-negative integer, or if
start
is greater than end
.
Example
const asyncIterable = asAsync([`sloth`, `more sloth`, `even more sloth`])
console.log(
await pipe(
asyncIterable,
sliceAsync(0, 3),
reduceAsync(toArray()),
),
)
//=> [ 'sloth', 'more sloth', 'even more sloth' ]
console.log(
await pipe(
asyncIterable,
sliceAsync(0, 42),
reduceAsync(toArray()),
),
)
//=> [ 'sloth', 'more sloth', 'even more sloth' ]
console.log(
await pipe(
asyncIterable,
sliceAsync(1, 3),
reduceAsync(toArray()),
),
)
//=> [ 'more sloth', 'even more sloth' ]
console.log(
await pipe(
asyncIterable,
sliceAsync(3, 5),
reduceAsync(toArray()),
),
)
//=> []
Since
v3.5.0