Variable: window()
constwindow: {<Size>(options): <Value>(iterable) =>Iterable<Value[]>; <Size,Value>(options,iterable):Iterable<Value[]>; }
Defined in: splices.d.ts:1158
Returns an iterable containing a rolling window of the values of iterable
as arrays of length size.
Call Signature
<
Size>(options): <Value>(iterable) =>Iterable<Value[]>
Type Parameters
Size
Size extends number
Parameters
options
WindowOptions<Size>
Returns
<
Value>(iterable):Iterable<Value[]>
Type Parameters
Value
Value
Parameters
iterable
Iterable<Value>
Returns
Iterable<Value[]>
Call Signature
<
Size,Value>(options,iterable):Iterable<Value[]>
Type Parameters
Size
Size extends number
Value
Value
Parameters
options
WindowOptions<Size>
iterable
Iterable<Value>
Returns
Iterable<Value[]>
Throws
if size is not a positive integer.
Example
console.log(
pipe(
[1, 2, 3, 4, 5, 6, `sloth`],
window(3),
reduce(toArray()),
),
)
//=> [ [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 5 ], [ 4, 5, 6 ], [ 5, 6, 'sloth' ] ]
console.log(
pipe(
[1, 2, 3, 4, 5, 6, `sloth`],
window({ size: 3, partialStart: true }),
reduce(toArray()),
),
)
//=> [ [ 1 ], [ 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 5 ], [ 4, 5, 6 ], [ 5, 6, 'sloth' ] ]
console.log(
pipe(
[1, 2, 3, 4, 5, 6, `sloth`],
window({ size: 3, partialStart: true, partialEnd: true }),
reduce(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