Methods
addToOrdered(arr, timestampSelector, …values)
Adds one or more elements to a time-ordered array of items, inserting them in chronological order.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array | destination array for new element(s). | |
timestampSelector |
timestampSelector | function to extract a timestamp from an element. | |
values |
any |
<repeatable> |
value(s) to add to the array. |
addToOrderedAndEvictBefore(arr, startTime, timestampSelector, …values)
Adds one or more elements to a time-ordered array of items, inserting them in chronological order. Any
elements in the array with a timestamp prior to the supplied startTime argument will be evicted from the
destination array.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array | destination array for new element(s). | |
startTime |
Date | number | start time (inclusive) of the first allowed element in the destination array. | |
timestampSelector |
timestampSelector | function to extract a timestamp from an element. | |
values |
any |
<repeatable> |
value(s) to add to the array. |
addToOrderedAndEvictOldest(arr, maxArraySize, timestampSelector, …values)
Adds one or more elements to a time-ordered array of items, inserting them in chronological order. If
the size of the destination array exceeds the supplied maxArraySize argument, the oldest elements in
the destination array will be evicted.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array | destination array for new element(s). | |
maxArraySize |
number | max allowed size of destination array before eviction begins. | |
timestampSelector |
timestampSelector | function to extract a timestamp from an element. | |
values |
any |
<repeatable> |
value(s) to add to the array. |
addToOrderedAndEvictSessions(arr, maxSessionCount, timestampSelector, idleThreshold, …values)
Adds one or more elements to a time-ordered array of items, inserting them in chronological order. If
the number of sessions in the destination array exceeds the supplied maxSessionCount argument, elements
in the oldest session(s) in the destination array will be evicted.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array | destination array for new element(s). | |
maxSessionCount |
number | max allowed number of sessions. | |
timestampSelector |
timestampSelector | function to extract a timestamp from an element. | |
idleThreshold |
number | max allowed time gap between elements before a new session is started, in milliseconds. | |
values |
any |
<repeatable> |
value(s) to add to the array. |
removeFirstItems(arr, count)
Perform in-place removal of the first N elements in an array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | array to be modified. |
count |
number | Number of elements to remove from the front of the array. |
toSessionWindows(sourceArray, timestampSelector, idleThreshold) → {Array.<TimeWindow>}
Transforms an ordered array into an array of session windows. The source array must be sorted chronologically.
Parameters:
Name | Type | Description |
---|---|---|
sourceArray |
Array | Array of time-ordered elements to transform. |
timestampSelector |
timestampSelector | Function to extract a timestamp from elements in the source array. |
idleThreshold |
number | max allowed time gap between elements before a new session is started, in milliseconds. |
Returns:
An array of TimeWindow instances.
- Type
- Array.<TimeWindow>
toSlidingWindows(sourceArray, timestampSelector, windowDuration, every, start, end) → {Array.<TimeWindow>}
Transforms an ordered array into an array of sliding windows. The source array must be sorted chronologically.
Parameters:
Name | Type | Description |
---|---|---|
sourceArray |
Array | Array of time-ordered elements to transform. |
timestampSelector |
timestampSelector | Function to extract a timestamp from elements in the source array. |
windowDuration |
number | Duration of each time window in milliseconds. This is a maximum value that will be shortened for the last window(s) in the returned sequence. |
every |
number | The period of time, in milliseconds, between the start of each sliding window. |
start |
number | Start time (inclusive) of the first sliding window, expressed as milliseconds elapsed since January 1, 1970 00:00:00 UTC. If undefined, the timestamp of the array's first element will be used. |
end |
number | End time (exclusive) for the last sliding window(s), expressed as milliseconds elapsed since January 1, 1970 00:00:00 UTC. If undefined, the timestamp of the array's last element will be used, and the last window's end time will be inclusive. |
Returns:
An array of TimeWindow instances.
- Type
- Array.<TimeWindow>
toTumblingWindows(sourceArray, timestampSelector, windowDuration, start, end) → {Array.<TimeWindow>}
Transforms an ordered array into an array of non-overlapped, fixed-time windows. The source array must be sorted chronologically.
Parameters:
Name | Type | Description |
---|---|---|
sourceArray |
Array | Array of time-ordered elements to transform. |
timestampSelector |
timestampSelector | Function to extract a timestamp from elements in the source array. |
windowDuration |
number | Duration of each time window in milliseconds. This is a maximum value that may be shortened for the last window in the returned sequence. |
start |
number | Start time (inclusive) of the first sliding window, expressed as milliseconds elapsed since January 1, 1970 00:00:00 UTC. If undefined, the timestamp of the array's first element will be used. |
end |
number | End time (exclusive) for the last sliding window(s), expressed as milliseconds elapsed since January 1, 1970 00:00:00 UTC. If undefined, the timestamp of the array's last element will be used, and the last window's end time will be inclusive. |
Returns:
An array of TimeWindow instances.
- Type
- Array.<TimeWindow>
Type Definitions
forEachCallback(currentValue, indexopt, windowopt)
Function that is executed on each element in a TimeWindow, taking three arguments:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
currentValue |
any | The current element in the TimeWindow being processed. | |
index |
number |
<optional> |
The index of the current element being processed in the array. |
window |
TimeWindow |
<optional> |
The TimeWindow that forEach() was called upon. |
- Source:
mapCallback(currentValue, indexopt, windowopt) → {any}
Function that produces an element for the new Array, taking three arguments:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
currentValue |
any | The current element in the TimeWindow being processed. | |
index |
number |
<optional> |
The index of the current element being processed in the array. |
window |
TimeWindow |
<optional> |
The TimeWindow that map() was called upon. |
- Source:
Returns:
Transformed element.
- Type
- any
predicateCallback(currentValue, indexopt, windowopt) → {boolean}
Predicate used to test each element the TimeWindow. Return true if the element satisifies the
condition, false otherwise. Three arguments are provided to this callback:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
currentValue |
any | The current element in the TimeWindow being tested. | |
index |
number |
<optional> |
The index of the current element being processed in the array. |
window |
TimeWindow |
<optional> |
The TimeWindow being evaluated. |
- Source:
Returns:
true if the element satisfies the condition, false otherwise.
- Type
- boolean
reduceCallback(accumulator, currentValue, indexopt, windowopt) → {any}
Reducer function to execute on each element in the TimeWindow, taking four arguments:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
accumulator |
any | The accumulator accumulates the callback's return values; it is the accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied. | |
currentValue |
any | The current element in the TimeWindow being processed. | |
index |
number |
<optional> |
The index of the current element being processed in the array. |
window |
TimeWindow |
<optional> |
The TimeWindow that reduce() was called upon. |
- Source:
Returns:
The accumulating value that is eventually returned to the reduce() caller. This returned value is assigned to the accumulator, whose value is remembered across each iteration throughout the window and ultimately becomes the final, single resulting value.
- Type
- any
timestampSelector(elem) → {number}
User-supplied callback that extracts a timestamp from an element in a time-ordered array of events.
Parameters:
Name | Type | Description |
---|---|---|
elem |
any | Timestamped element in a time-ordered array of events. |
Returns:
The time that the elem argument occurred, represented as milliseconds elapsed since January 1, 1970 00:00:00 UTC.
- Type
- number