LaterList
Handle asynchronous events as an array that will arrive eventually: a LaterList.
Install
Available via npm
npm install laterlist
Usage
var Flood = Flood; // Works like an arrayFlood ; // 10 // even when callbacks resolve asynchronouslyFlood ; // Sum total of page views of those users.
Source
https://github.com/will-weiss/LaterList
License
Released under the MIT License.
LaterList
A LaterList is a linked list which may be used to process values that arrive or are processed asynchronously. As in many implementations of streams, listeners may be added to instances of LaterList to process incoming values. There are however some differences that make LaterList useful.
- Familiar API: Array methods are implemented with an identical syntax. Methods that return or mutate arrays return LaterLists. Other methods wrap their return values in a Promise.
- Preservation: Listeners will process a whole list even if they are added after values have been pushed onto the list. Data is never dropped.
- Indexing: Values are indexed by the order in which they are pushed.
- Fully Asynchronous: A LaterList may be mapped, reduced, filtered, etc. using functions that return Promises. LaterLists process the resolved values of Promises pushed onto them.
- Easy Chaining: Methods of LaterLists may be chained together. Values are passed along the chain even before the original list has ended and uncaught exceptions propogate down the chain.
- Flexible: The two types of LaterLists - Flood and Relay - share an identical API but differ slightly in when their elements are processed. Elements of a Flood are processed as soon as they are available. Elements of a Relay are processed when processing of all prior elements is done. So, Floods have higher throughput while Relays preserve order, making each suitable for different contexts.
- Unbounded: LaterLists may be pushed onto indefinitely without memory overload. When a LaterList is closed, adding new listeners is disabled so that elements processed by existing listeners may be garbage collected.
- Active Listeners: Listeners of a LaterList are not simply callbacks; they are their own class and maintain state. As listeners keep a reference to their unprocessed elements, values may be pushed onto a LaterList more quickly than they are processed without needing to worry about backpressure for all but the most memory-intensive applications.
- Lightweight: LaterList has a minimal codebase and no dependencies relying only on a JS environment that supports the Promise/A+ specification.
Classes
- LaterList/Flood ⇐
LaterList
A Flood is a LaterList for which values are processed immediately.
- LaterList/Relay ⇐
LaterList
A Relay is a LaterList for which order is preserved when listened to.
- LaterList
A LaterList is a linked list which may be used to process values that arrive or are processed asynchronously.
[LaterList](#LaterList)
A Flood is a LaterList for which values are processed immediately.
Kind: global class
Extends: LaterList
- LaterList/Flood ⇐
LaterList
- .length :
Number
- .addListener(onData, onEnd, initialValue)
- .push(...values) ⇒
Number
- .revive(fn, err)
- .end(err)
- .link(onData) ⇒
- .close()
- .consume(onData, initialValue) ⇒
Promise.<*>
- .value() ⇒
Promise.<Array.<*>>
- .atIndex(index) ⇒
*
- .when() ⇒
Promise
- .concat(...lists) ⇒
LaterList
- .every(predicate, thisArg) ⇒
Promise.<Boolean>
- .filter(predicate, thisArg) ⇒
LaterList
- .find(predicate, thisArg) ⇒
Promise.<*>
- .findIndex(predicate, thisArg) ⇒
Promise.<Number>
- .forEach(lambda, thisArg) ⇒
Promise.<undefined>
- .includes(toMatch, fromIndex) ⇒
Promise.<Boolean>
- .indexOf(toMatch) ⇒
Promise.<Number>
- .join(separator) ⇒
Promise.<String>
- .lastIndexOf(toMatch) ⇒
Promise.<Number>
- .map(lambda, thisArg) ⇒
LaterList
- .reduce(lambda, initialValue) ⇒
Promise.<*>
- .reduceRight(lambda, initialValue) ⇒
Promise.<*>
- .reverse() ⇒
LaterList
- .slice(begin, end) ⇒
LaterList
- .some(predicate, thisArg) ⇒
Promise.<Boolean>
- .sort(compare) ⇒
LaterList
- .splice(begin, deleteCount, ...additions) ⇒
LaterList
- .length :
Number
laterList/Flood.length : Number of nodes in the list.
Kind: instance property of LaterList/Flood
laterList/Flood.addListener(onData, onEnd, initialValue)
Adds a listener which processes values of this flood as soon as they arrive.
Kind: instance method of LaterList/Flood
Param | Type | Description |
---|---|---|
onData | function |
A function applied to each node. |
onEnd | function |
A function to execute on end. |
initialValue | * |
An initial value. |
Number
laterList/Flood.push(...values) ⇒ Adds a values to the list's tail. Pending listeners are revived and shifted.
Kind: instance method of LaterList/Flood
Returns: Number
- The new length of the list.
Param | Type | Description |
---|---|---|
...values | * |
The values to add to the end of the list. |
laterList/Flood.revive(fn, err)
Executes a Listener.prototype function on each pending listener.
Kind: instance method of LaterList/Flood
Param | Type | Description |
---|---|---|
fn | function |
A Listener.prototype function. |
err | Error |
Optional. An error to pass to pending listeners. |
laterList/Flood.end(err)
Indicates that no more nodes will be added to the list. If an argument is present it is interpreted as an error which will immediately end all listeners. If no argument is present, listeners will end when they have processed all nodes of the list. Subsequent calls of push and end on this list will throw.
Kind: instance method of LaterList/Flood
Param | Type | Description |
---|---|---|
err | error |
An optional error. |
laterList/Flood.link(onData) ⇒
Return a new LaterList instance whose nodes are the result of applying the supplied onData function to each node of this list.
Kind: instance method of LaterList/Flood
Returns: LaterList A LaterList of the same subclass as this list.
Param | Type | Description |
---|---|---|
onData | function |
A function to process nodes of this list executed in the context of the listener. |
laterList/Flood.close()
Indicates that no more listeners will be added to this list. The reference to the head of the list is removed so that nodes processed by each listener may be garbage colllected. Subsequent calls of close, atIndex and adding of listeners on this list will throw as these methods require a reference to the list's head.
Kind: instance method of LaterList/Flood
Promise.<*>
laterList/Flood.consume(onData, initialValue) ⇒ Returns a promise that resolves with the final value of a listener.
Kind: instance method of LaterList/Flood
Returns: Promise.<*>
- The result of the computation of the listener.
Param | Type | Description |
---|---|---|
onData | function |
A function to process nodes of this list executed in the context of the listener. |
initialValue | * |
An initial value set on the listener. |
Promise.<Array.<*>>
laterList/Flood.value() ⇒ Collect the nodes of the list as an array.
Kind: instance method of LaterList/Flood
Returns: Promise.<Array.<*>>
- Resolves with the values of the list's nodes.
*
laterList/Flood.atIndex(index) ⇒ Looks up the value of the node at the supplied index. Returns undefined if the index is not a number or out of bounds.
Kind: instance method of LaterList/Flood
Returns: *
- The value of the node at that index.
Param | Type | Description |
---|---|---|
index | Number |
An index of the list. |
Promise
laterList/Flood.when() ⇒ Resolves with undefined if the list ends without error, rejects if the list ends with an error.
Kind: instance method of LaterList/Flood
LaterList
laterList/Flood.concat(...lists) ⇒ Returns a new list comprised of the list on which it is called joined with the list-like(s) and/or value(s) provided as arguments.
Kind: instance method of LaterList/Flood
Returns: LaterList
- A list whose nodes have the concatenated values of the
supplied arguments.
Param | Type | Description |
---|---|---|
...lists | Object.<{forEach: function()}> |
list-likes to concatenate to this list. |
Promise.<Boolean>
laterList/Flood.every(predicate, thisArg) ⇒ Tests whether all nodes in the list pass the test implemented by the provided function.
Kind: instance method of LaterList/Flood
Returns: Promise.<Boolean>
- true if the predicate is true for all nodes in
the list, false otherwise.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
LaterList
laterList/Flood.filter(predicate, thisArg) ⇒ Creates a new LaterList with all nodes that pass the test implemented by the provided function.
Kind: instance method of LaterList/Flood
Returns: LaterList
- A list with the filtered values of the original list.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<*>
laterList/Flood.find(predicate, thisArg) ⇒ Returns a value in the list, if a node in the list satisfies the provided testing function. Otherwise undefined is returned.
Kind: instance method of LaterList/Flood
Returns: Promise.<*>
- The value of the first node to satisfy the predicate.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<Number>
laterList/Flood.findIndex(predicate, thisArg) ⇒ Returns an index in the list, if a node in the list satisfies the provided testing function. Otherwise -1 is returned.
Kind: instance method of LaterList/Flood
Returns: Promise.<Number>
- The first index of a node satisfying the
predicate.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<undefined>
laterList/Flood.forEach(lambda, thisArg) ⇒ Executes a provided function once per node.
Kind: instance method of LaterList/Flood
Returns: Promise.<undefined>
- Resolves when processing has ended.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
thisArg | Object |
Optional. Value to use as this when executing the lambda. |
Promise.<Boolean>
laterList/Flood.includes(toMatch, fromIndex) ⇒ Determines whether a list includes a certain element, returning true or false as appropriate.
Kind: instance method of LaterList/Flood
Returns: Promise.<Boolean>
- Whether the value appears in the list.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
fromIndex | Number |
Optional. The position in this list at which to begin searching for searchElement; defaults to 0. |
Promise.<Number>
laterList/Flood.indexOf(toMatch) ⇒ Returns the first index at which a given value can be found in the list, or -1 if it is not present.
Kind: instance method of LaterList/Flood
Returns: Promise.<Number>
- The first index of a node with the supplied value.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
Promise.<String>
laterList/Flood.join(separator) ⇒ Joins all values of a list into a string.
Kind: instance method of LaterList/Flood
Param | Type | Description |
---|---|---|
separator | String |
Specifies a string to separate each value of the list. |
Promise.<Number>
laterList/Flood.lastIndexOf(toMatch) ⇒ Returns the last index at which a given value can be found in the list, or -1 if it is not present.
Kind: instance method of LaterList/Flood
Returns: Promise.<Number>
- The last index of a node with the supplied value.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
LaterList
laterList/Flood.map(lambda, thisArg) ⇒ Creates a new list with the results of calling a provided function on every node in this list.
Kind: instance method of LaterList/Flood
Returns: LaterList
- A new list with the results of mapping the lambda over
this list.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
thisArg | Object |
Optional. Value to use as this when executing the lambda. |
Promise.<*>
laterList/Flood.reduce(lambda, initialValue) ⇒ Applies a function against an accumulator and each node of the list (from left-to-right) has to reduce it to a single value.
Kind: instance method of LaterList/Flood
Returns: Promise.<*>
- The reduced value.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
initialValue | * |
Optional. Object to use as the first argument to the first call of the lambda. |
Promise.<*>
laterList/Flood.reduceRight(lambda, initialValue) ⇒ Applies a function against an accumulator and each node of the list (from right-to-left) has to reduce it to a single value. Note that this operation can only commence when the list has ended and been reversed. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList/Flood
Returns: Promise.<*>
- The reduced value.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
initialValue | * |
Optional. Object to use as the first argument to the first call of the lambda. |
LaterList
laterList/Flood.reverse() ⇒ Returns a reversed list. The first list node becomes the last and the last becomes the first. Note that while this operation maintains a copy of each node and can only complete when the list has ended. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList/Flood
Returns: LaterList
- A new list with the values of this list reversed.
LaterList
laterList/Flood.slice(begin, end) ⇒ Returns a shallow copy of a portion of a list into a new list.
Kind: instance method of LaterList/Flood
Returns: LaterList
- A list with the sliced portion of this list.
Param | Type | Description |
---|---|---|
begin | Number |
An index to begin at. |
end | Number |
An index to end at. |
Promise.<Boolean>
laterList/Flood.some(predicate, thisArg) ⇒ Tests whether some element in the list passes the test implemented by the provided function.
Kind: instance method of LaterList/Flood
Returns: Promise.<Boolean>
- true if the predicate is true for some node in
the list, false otherwise.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing predicate. |
LaterList
laterList/Flood.sort(compare) ⇒ Returns a LaterList with the sorted nodes of this list. Note that this operation can only commence when the list has ended and requires all the values of the list collected in an array before they are sorted and copied to the resulting list. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList/Flood
Returns: LaterList
- A new list with sorted values from this list.
Param | Type | Description |
---|---|---|
compare | function |
Optional. A function on which to sort. |
LaterList
laterList/Flood.splice(begin, deleteCount, ...additions) ⇒ Returns a new list with some nodes in this list removed and/or some nodes added.
Kind: instance method of LaterList/Flood
Returns: LaterList
- A new list with the modified values from this list.
Param | Type | Description |
---|---|---|
begin | Number |
An index to begin at. |
deleteCount | Number |
The number of elements to remove. |
...additions | * |
Values to add to the list. |
LaterList
LaterList/Relay ⇐ A Relay is a LaterList for which order is preserved when listened to.
Kind: global class
Extends: LaterList
- LaterList/Relay ⇐
LaterList
- .length :
Number
- .addListener(onData, onEnd, initialValue)
- .push(...values) ⇒
Number
- .revive(fn, err)
- .end(err)
- .link(onData) ⇒
- .close()
- .consume(onData, initialValue) ⇒
Promise.<*>
- .value() ⇒
Promise.<Array.<*>>
- .atIndex(index) ⇒
*
- .when() ⇒
Promise
- .concat(...lists) ⇒
LaterList
- .every(predicate, thisArg) ⇒
Promise.<Boolean>
- .filter(predicate, thisArg) ⇒
LaterList
- .find(predicate, thisArg) ⇒
Promise.<*>
- .findIndex(predicate, thisArg) ⇒
Promise.<Number>
- .forEach(lambda, thisArg) ⇒
Promise.<undefined>
- .includes(toMatch, fromIndex) ⇒
Promise.<Boolean>
- .indexOf(toMatch) ⇒
Promise.<Number>
- .join(separator) ⇒
Promise.<String>
- .lastIndexOf(toMatch) ⇒
Promise.<Number>
- .map(lambda, thisArg) ⇒
LaterList
- .reduce(lambda, initialValue) ⇒
Promise.<*>
- .reduceRight(lambda, initialValue) ⇒
Promise.<*>
- .reverse() ⇒
LaterList
- .slice(begin, end) ⇒
LaterList
- .some(predicate, thisArg) ⇒
Promise.<Boolean>
- .sort(compare) ⇒
LaterList
- .splice(begin, deleteCount, ...additions) ⇒
LaterList
- .length :
Number
laterList/Relay.length : Number of nodes in the list.
Kind: instance property of LaterList/Relay
laterList/Relay.addListener(onData, onEnd, initialValue)
Adds a listener which processes values of this relay when all prior values have been processed.
Kind: instance method of LaterList/Relay
Param | Type | Description |
---|---|---|
onData | function |
A function applied to each node. |
onEnd | function |
A function to execute on end. |
initialValue | * |
An initial value. |
Number
laterList/Relay.push(...values) ⇒ Adds a values to the list's tail. Pending listeners are revived and shifted.
Kind: instance method of LaterList/Relay
Returns: Number
- The new length of the list.
Param | Type | Description |
---|---|---|
...values | * |
The values to add to the end of the list. |
laterList/Relay.revive(fn, err)
Executes a Listener.prototype function on each pending listener.
Kind: instance method of LaterList/Relay
Param | Type | Description |
---|---|---|
fn | function |
A Listener.prototype function. |
err | Error |
Optional. An error to pass to pending listeners. |
laterList/Relay.end(err)
Indicates that no more nodes will be added to the list. If an argument is present it is interpreted as an error which will immediately end all listeners. If no argument is present, listeners will end when they have processed all nodes of the list. Subsequent calls of push and end on this list will throw.
Kind: instance method of LaterList/Relay
Param | Type | Description |
---|---|---|
err | error |
An optional error. |
laterList/Relay.link(onData) ⇒
Return a new LaterList instance whose nodes are the result of applying the supplied onData function to each node of this list.
Kind: instance method of LaterList/Relay
Returns: LaterList A LaterList of the same subclass as this list.
Param | Type | Description |
---|---|---|
onData | function |
A function to process nodes of this list executed in the context of the listener. |
laterList/Relay.close()
Indicates that no more listeners will be added to this list. The reference to the head of the list is removed so that nodes processed by each listener may be garbage colllected. Subsequent calls of close, atIndex and adding of listeners on this list will throw as these methods require a reference to the list's head.
Kind: instance method of LaterList/Relay
Promise.<*>
laterList/Relay.consume(onData, initialValue) ⇒ Returns a promise that resolves with the final value of a listener.
Kind: instance method of LaterList/Relay
Returns: Promise.<*>
- The result of the computation of the listener.
Param | Type | Description |
---|---|---|
onData | function |
A function to process nodes of this list executed in the context of the listener. |
initialValue | * |
An initial value set on the listener. |
Promise.<Array.<*>>
laterList/Relay.value() ⇒ Collect the nodes of the list as an array.
Kind: instance method of LaterList/Relay
Returns: Promise.<Array.<*>>
- Resolves with the values of the list's nodes.
*
laterList/Relay.atIndex(index) ⇒ Looks up the value of the node at the supplied index. Returns undefined if the index is not a number or out of bounds.
Kind: instance method of LaterList/Relay
Returns: *
- The value of the node at that index.
Param | Type | Description |
---|---|---|
index | Number |
An index of the list. |
Promise
laterList/Relay.when() ⇒ Resolves with undefined if the list ends without error, rejects if the list ends with an error.
Kind: instance method of LaterList/Relay
LaterList
laterList/Relay.concat(...lists) ⇒ Returns a new list comprised of the list on which it is called joined with the list-like(s) and/or value(s) provided as arguments.
Kind: instance method of LaterList/Relay
Returns: LaterList
- A list whose nodes have the concatenated values of the
supplied arguments.
Param | Type | Description |
---|---|---|
...lists | Object.<{forEach: function()}> |
list-likes to concatenate to this list. |
Promise.<Boolean>
laterList/Relay.every(predicate, thisArg) ⇒ Tests whether all nodes in the list pass the test implemented by the provided function.
Kind: instance method of LaterList/Relay
Returns: Promise.<Boolean>
- true if the predicate is true for all nodes in
the list, false otherwise.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
LaterList
laterList/Relay.filter(predicate, thisArg) ⇒ Creates a new LaterList with all nodes that pass the test implemented by the provided function.
Kind: instance method of LaterList/Relay
Returns: LaterList
- A list with the filtered values of the original list.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<*>
laterList/Relay.find(predicate, thisArg) ⇒ Returns a value in the list, if a node in the list satisfies the provided testing function. Otherwise undefined is returned.
Kind: instance method of LaterList/Relay
Returns: Promise.<*>
- The value of the first node to satisfy the predicate.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<Number>
laterList/Relay.findIndex(predicate, thisArg) ⇒ Returns an index in the list, if a node in the list satisfies the provided testing function. Otherwise -1 is returned.
Kind: instance method of LaterList/Relay
Returns: Promise.<Number>
- The first index of a node satisfying the
predicate.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<undefined>
laterList/Relay.forEach(lambda, thisArg) ⇒ Executes a provided function once per node.
Kind: instance method of LaterList/Relay
Returns: Promise.<undefined>
- Resolves when processing has ended.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
thisArg | Object |
Optional. Value to use as this when executing the lambda. |
Promise.<Boolean>
laterList/Relay.includes(toMatch, fromIndex) ⇒ Determines whether a list includes a certain element, returning true or false as appropriate.
Kind: instance method of LaterList/Relay
Returns: Promise.<Boolean>
- Whether the value appears in the list.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
fromIndex | Number |
Optional. The position in this list at which to begin searching for searchElement; defaults to 0. |
Promise.<Number>
laterList/Relay.indexOf(toMatch) ⇒ Returns the first index at which a given value can be found in the list, or -1 if it is not present.
Kind: instance method of LaterList/Relay
Returns: Promise.<Number>
- The first index of a node with the supplied value.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
Promise.<String>
laterList/Relay.join(separator) ⇒ Joins all values of a list into a string.
Kind: instance method of LaterList/Relay
Param | Type | Description |
---|---|---|
separator | String |
Specifies a string to separate each value of the list. |
Promise.<Number>
laterList/Relay.lastIndexOf(toMatch) ⇒ Returns the last index at which a given value can be found in the list, or -1 if it is not present.
Kind: instance method of LaterList/Relay
Returns: Promise.<Number>
- The last index of a node with the supplied value.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
LaterList
laterList/Relay.map(lambda, thisArg) ⇒ Creates a new list with the results of calling a provided function on every node in this list.
Kind: instance method of LaterList/Relay
Returns: LaterList
- A new list with the results of mapping the lambda over
this list.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
thisArg | Object |
Optional. Value to use as this when executing the lambda. |
Promise.<*>
laterList/Relay.reduce(lambda, initialValue) ⇒ Applies a function against an accumulator and each node of the list (from left-to-right) has to reduce it to a single value.
Kind: instance method of LaterList/Relay
Returns: Promise.<*>
- The reduced value.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
initialValue | * |
Optional. Object to use as the first argument to the first call of the lambda. |
Promise.<*>
laterList/Relay.reduceRight(lambda, initialValue) ⇒ Applies a function against an accumulator and each node of the list (from right-to-left) has to reduce it to a single value. Note that this operation can only commence when the list has ended and been reversed. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList/Relay
Returns: Promise.<*>
- The reduced value.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
initialValue | * |
Optional. Object to use as the first argument to the first call of the lambda. |
LaterList
laterList/Relay.reverse() ⇒ Returns a reversed list. The first list node becomes the last and the last becomes the first. Note that while this operation maintains a copy of each node and can only complete when the list has ended. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList/Relay
Returns: LaterList
- A new list with the values of this list reversed.
LaterList
laterList/Relay.slice(begin, end) ⇒ Returns a shallow copy of a portion of a list into a new list.
Kind: instance method of LaterList/Relay
Returns: LaterList
- A list with the sliced portion of this list.
Param | Type | Description |
---|---|---|
begin | Number |
An index to begin at. |
end | Number |
An index to end at. |
Promise.<Boolean>
laterList/Relay.some(predicate, thisArg) ⇒ Tests whether some element in the list passes the test implemented by the provided function.
Kind: instance method of LaterList/Relay
Returns: Promise.<Boolean>
- true if the predicate is true for some node in
the list, false otherwise.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing predicate. |
LaterList
laterList/Relay.sort(compare) ⇒ Returns a LaterList with the sorted nodes of this list. Note that this operation can only commence when the list has ended and requires all the values of the list collected in an array before they are sorted and copied to the resulting list. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList/Relay
Returns: LaterList
- A new list with sorted values from this list.
Param | Type | Description |
---|---|---|
compare | function |
Optional. A function on which to sort. |
LaterList
laterList/Relay.splice(begin, deleteCount, ...additions) ⇒ Returns a new list with some nodes in this list removed and/or some nodes added.
Kind: instance method of LaterList/Relay
Returns: LaterList
- A new list with the modified values from this list.
Param | Type | Description |
---|---|---|
begin | Number |
An index to begin at. |
deleteCount | Number |
The number of elements to remove. |
...additions | * |
Values to add to the list. |
LaterList
A LaterList is a linked list which may be used to process values that arrive or are processed asynchronously.
Kind: global class
- LaterList
- instance
- .length :
Number
- .push(...values) ⇒
Number
- .revive(fn, err)
- .end(err)
- .link(onData) ⇒
- .close()
- .consume(onData, initialValue) ⇒
Promise.<*>
- .value() ⇒
Promise.<Array.<*>>
- .atIndex(index) ⇒
*
- .when() ⇒
Promise
- .concat(...lists) ⇒
LaterList
- .every(predicate, thisArg) ⇒
Promise.<Boolean>
- .filter(predicate, thisArg) ⇒
LaterList
- .find(predicate, thisArg) ⇒
Promise.<*>
- .findIndex(predicate, thisArg) ⇒
Promise.<Number>
- .forEach(lambda, thisArg) ⇒
Promise.<undefined>
- .includes(toMatch, fromIndex) ⇒
Promise.<Boolean>
- .indexOf(toMatch) ⇒
Promise.<Number>
- .join(separator) ⇒
Promise.<String>
- .lastIndexOf(toMatch) ⇒
Promise.<Number>
- .map(lambda, thisArg) ⇒
LaterList
- .reduce(lambda, initialValue) ⇒
Promise.<*>
- .reduceRight(lambda, initialValue) ⇒
Promise.<*>
- .reverse() ⇒
LaterList
- .slice(begin, end) ⇒
LaterList
- .some(predicate, thisArg) ⇒
Promise.<Boolean>
- .sort(compare) ⇒
LaterList
- .splice(begin, deleteCount, ...additions) ⇒
LaterList
- .length :
- static
- instance
Number
laterList.length : Number of nodes in the list.
Kind: instance property of LaterList
Number
laterList.push(...values) ⇒ Adds a values to the list's tail. Pending listeners are revived and shifted.
Kind: instance method of LaterList
Returns: Number
- The new length of the list.
Param | Type | Description |
---|---|---|
...values | * |
The values to add to the end of the list. |
laterList.revive(fn, err)
Executes a Listener.prototype function on each pending listener.
Kind: instance method of LaterList
Param | Type | Description |
---|---|---|
fn | function |
A Listener.prototype function. |
err | Error |
Optional. An error to pass to pending listeners. |
laterList.end(err)
Indicates that no more nodes will be added to the list. If an argument is present it is interpreted as an error which will immediately end all listeners. If no argument is present, listeners will end when they have processed all nodes of the list. Subsequent calls of push and end on this list will throw.
Kind: instance method of LaterList
Param | Type | Description |
---|---|---|
err | error |
An optional error. |
laterList.link(onData) ⇒
Return a new LaterList instance whose nodes are the result of applying the supplied onData function to each node of this list.
Kind: instance method of LaterList
Returns: LaterList A LaterList of the same subclass as this list.
Param | Type | Description |
---|---|---|
onData | function |
A function to process nodes of this list executed in the context of the listener. |
laterList.close()
Indicates that no more listeners will be added to this list. The reference to the head of the list is removed so that nodes processed by each listener may be garbage colllected. Subsequent calls of close, atIndex and adding of listeners on this list will throw as these methods require a reference to the list's head.
Kind: instance method of LaterList
Promise.<*>
laterList.consume(onData, initialValue) ⇒ Returns a promise that resolves with the final value of a listener.
Kind: instance method of LaterList
Returns: Promise.<*>
- The result of the computation of the listener.
Param | Type | Description |
---|---|---|
onData | function |
A function to process nodes of this list executed in the context of the listener. |
initialValue | * |
An initial value set on the listener. |
Promise.<Array.<*>>
laterList.value() ⇒ Collect the nodes of the list as an array.
Kind: instance method of LaterList
Returns: Promise.<Array.<*>>
- Resolves with the values of the list's nodes.
*
laterList.atIndex(index) ⇒ Looks up the value of the node at the supplied index. Returns undefined if the index is not a number or out of bounds.
Kind: instance method of LaterList
Returns: *
- The value of the node at that index.
Param | Type | Description |
---|---|---|
index | Number |
An index of the list. |
Promise
laterList.when() ⇒ Resolves with undefined if the list ends without error, rejects if the list ends with an error.
Kind: instance method of LaterList
LaterList
laterList.concat(...lists) ⇒ Returns a new list comprised of the list on which it is called joined with the list-like(s) and/or value(s) provided as arguments.
Kind: instance method of LaterList
Returns: LaterList
- A list whose nodes have the concatenated values of the
supplied arguments.
Param | Type | Description |
---|---|---|
...lists | Object.<{forEach: function()}> |
list-likes to concatenate to this list. |
Promise.<Boolean>
laterList.every(predicate, thisArg) ⇒ Tests whether all nodes in the list pass the test implemented by the provided function.
Kind: instance method of LaterList
Returns: Promise.<Boolean>
- true if the predicate is true for all nodes in
the list, false otherwise.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
LaterList
laterList.filter(predicate, thisArg) ⇒ Creates a new LaterList with all nodes that pass the test implemented by the provided function.
Kind: instance method of LaterList
Returns: LaterList
- A list with the filtered values of the original list.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<*>
laterList.find(predicate, thisArg) ⇒ Returns a value in the list, if a node in the list satisfies the provided testing function. Otherwise undefined is returned.
Kind: instance method of LaterList
Returns: Promise.<*>
- The value of the first node to satisfy the predicate.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<Number>
laterList.findIndex(predicate, thisArg) ⇒ Returns an index in the list, if a node in the list satisfies the provided testing function. Otherwise -1 is returned.
Kind: instance method of LaterList
Returns: Promise.<Number>
- The first index of a node satisfying the
predicate.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing the predicate. |
Promise.<undefined>
laterList.forEach(lambda, thisArg) ⇒ Executes a provided function once per node.
Kind: instance method of LaterList
Returns: Promise.<undefined>
- Resolves when processing has ended.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
thisArg | Object |
Optional. Value to use as this when executing the lambda. |
Promise.<Boolean>
laterList.includes(toMatch, fromIndex) ⇒ Determines whether a list includes a certain element, returning true or false as appropriate.
Kind: instance method of LaterList
Returns: Promise.<Boolean>
- Whether the value appears in the list.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
fromIndex | Number |
Optional. The position in this list at which to begin searching for searchElement; defaults to 0. |
Promise.<Number>
laterList.indexOf(toMatch) ⇒ Returns the first index at which a given value can be found in the list, or -1 if it is not present.
Kind: instance method of LaterList
Returns: Promise.<Number>
- The first index of a node with the supplied value.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
Promise.<String>
laterList.join(separator) ⇒ Joins all values of a list into a string.
Kind: instance method of LaterList
Param | Type | Description |
---|---|---|
separator | String |
Specifies a string to separate each value of the list. |
Promise.<Number>
laterList.lastIndexOf(toMatch) ⇒ Returns the last index at which a given value can be found in the list, or -1 if it is not present.
Kind: instance method of LaterList
Returns: Promise.<Number>
- The last index of a node with the supplied value.
Param | Type | Description |
---|---|---|
toMatch | * |
A value to match. |
LaterList
laterList.map(lambda, thisArg) ⇒ Creates a new list with the results of calling a provided function on every node in this list.
Kind: instance method of LaterList
Returns: LaterList
- A new list with the results of mapping the lambda over
this list.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
thisArg | Object |
Optional. Value to use as this when executing the lambda. |
Promise.<*>
laterList.reduce(lambda, initialValue) ⇒ Applies a function against an accumulator and each node of the list (from left-to-right) has to reduce it to a single value.
Kind: instance method of LaterList
Returns: Promise.<*>
- The reduced value.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
initialValue | * |
Optional. Object to use as the first argument to the first call of the lambda. |
Promise.<*>
laterList.reduceRight(lambda, initialValue) ⇒ Applies a function against an accumulator and each node of the list (from right-to-left) has to reduce it to a single value. Note that this operation can only commence when the list has ended and been reversed. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList
Returns: Promise.<*>
- The reduced value.
Param | Type | Description |
---|---|---|
lambda | function |
Function to execute for each element |
initialValue | * |
Optional. Object to use as the first argument to the first call of the lambda. |
LaterList
laterList.reverse() ⇒ Returns a reversed list. The first list node becomes the last and the last becomes the first. Note that while this operation maintains a copy of each node and can only complete when the list has ended. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList
Returns: LaterList
- A new list with the values of this list reversed.
LaterList
laterList.slice(begin, end) ⇒ Returns a shallow copy of a portion of a list into a new list.
Kind: instance method of LaterList
Returns: LaterList
- A list with the sliced portion of this list.
Param | Type | Description |
---|---|---|
begin | Number |
An index to begin at. |
end | Number |
An index to end at. |
Promise.<Boolean>
laterList.some(predicate, thisArg) ⇒ Tests whether some element in the list passes the test implemented by the provided function.
Kind: instance method of LaterList
Returns: Promise.<Boolean>
- true if the predicate is true for some node in
the list, false otherwise.
Param | Type | Description |
---|---|---|
predicate | function |
Function to test for each element. |
thisArg | Object |
Optional. Value to use as this when executing predicate. |
LaterList
laterList.sort(compare) ⇒ Returns a LaterList with the sorted nodes of this list. Note that this operation can only commence when the list has ended and requires all the values of the list collected in an array before they are sorted and copied to the resulting list. As this is computationally expensive, finding other approaches is recommended.
Kind: instance method of LaterList
Returns: LaterList
- A new list with sorted values from this list.
Param | Type | Description |
---|---|---|
compare | function |
Optional. A function on which to sort. |
LaterList
laterList.splice(begin, deleteCount, ...additions) ⇒ Returns a new list with some nodes in this list removed and/or some nodes added.
Kind: instance method of LaterList
Returns: LaterList
- A new list with the modified values from this list.
Param | Type | Description |
---|---|---|
begin | Number |
An index to begin at. |
deleteCount | Number |
The number of elements to remove. |
...additions | * |
Values to add to the list. |
LaterList.from(listLike, mapFn, thisArg) ⇒
Creates a new LaterList instance from an list-like object with a forEach method. The new list ends when the execution of forEach resolves.
Kind: static method of LaterList
Returns: LaterList An instance of LaterList whose nodes have values equal to
those of the supplied list-like.
Param | Type | Description |
---|---|---|
listLike | Object.<{forEach: function()}> |
An object to create a list from. |
mapFn | function |
Optional. Map function to call on every element of the list. |
thisArg | Object |
Optional. Value to use as this when executing mapFn. |
LaterList.of(...values) ⇒
Creates a new LaterList instance with a variable number of arguments.
Kind: static method of LaterList
Returns: LaterList An instance of LaterList whose nodes have values equal to
those of the supplied arguments.
Param | Type | Description |
---|---|---|
...values | * |
The values to add to a new list. |