Skip to main content

Variable: windowAsync()

const windowAsync: {<Size>(options): <Value>(asyncIterable) => AsyncIterable<Value[]>; <Size, Value>(options, asyncIterable): AsyncIterable<Value[]>; }

Defined in: splices.d.ts:1074

Returns an async iterable containing a rolling window of the values of asyncIterable as arrays of length size.

Call Signature

<Size>(options): <Value>(asyncIterable) => AsyncIterable<Value[]>

Type Parameters

Size

Size extends number

Parameters

options

WindowOptions<Size>

Returns

<Value>(asyncIterable): AsyncIterable<Value[]>

Type Parameters

Value

Value

Parameters

asyncIterable

AsyncIterable<Value>

Returns

AsyncIterable<Value[]>

Call Signature

<Size, Value>(options, asyncIterable): AsyncIterable<Value[]>

Type Parameters

Size

Size extends number

Value

Value

Parameters

options

WindowOptions<Size>

asyncIterable

AsyncIterable<Value>

Returns

AsyncIterable<Value[]>

Throws

if size is not a positive integer.

Example

console.log(
await pipe(
asAsync([1, 2, 3, 4, 5, 6, `sloth`]),
windowAsync(3),
reduceAsync(toArray()),
),
)
//=> [ [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 5 ], [ 4, 5, 6 ], [ 5, 6, 'sloth' ] ]

console.log(
await pipe(
asAsync([1, 2, 3, 4, 5, 6, `sloth`]),
windowAsync({ size: 3, partialStart: true }),
reduceAsync(toArray()),
),
)
//=> [ [ 1 ], [ 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 5 ], [ 4, 5, 6 ], [ 5, 6, 'sloth' ] ]

console.log(
await pipe(
asAsync([1, 2, 3, 4, 5, 6, `sloth`]),
windowAsync({ size: 3, partialStart: true, partialEnd: true }),
reduceAsync(toArray()),
),
)
//=> [ [ 1 ], [ 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 5 ], [ 4, 5, 6 ], [ 5, 6, 'sloth' ], [ 6, 'sloth' ], [ 'sloth' ] ]

Since

v2.0.0