laterlist v1.0.1
LaterList
Handle asynchronous events as an array that will arrive eventually: a LaterList.
Install
Available via npm
npm install laterlist
Usage
var Flood = require('LaterList').Flood;
// Works like an array
Flood.of(1,2,3,4,5)
.map(function(n) {
return n + 2;
}).filter(function(n) {
return n % 2 === 0;
}).reduce(function(total, n) {
return total + n;
}, 0).then(console.log); // 10
// even when callbacks resolve asynchronously
Flood.from(someUserIds)
.map(db.getUserByIdAsync)
.reduce(function(pageViews, user) {
return pageViews + user.pageViews;
}, 0).then(console.log); // 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.
Classes
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
laterList/Flood.length : Number
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. |
laterList/Flood.push(...values) ⇒ Number
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
laterList/Flood.consume(onData, initialValue) ⇒ Promise.<*>
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. |
laterList/Flood.value() ⇒ Promise.<Array.<*>>
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. |
laterList/Flood.when() ⇒ Promise
Resolves with undefined if the list ends without error, rejects if the list ends with an error.
Kind: instance method of LaterList/Flood
laterList/Flood.concat(...lists) ⇒ LaterList
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. |
laterList/Flood.every(predicate, thisArg) ⇒ Promise.<Boolean>
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/Flood.filter(predicate, thisArg) ⇒ LaterList
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. |
laterList/Flood.find(predicate, thisArg) ⇒ Promise.<*>
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. |
laterList/Flood.findIndex(predicate, thisArg) ⇒ Promise.<Number>
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. |
laterList/Flood.forEach(lambda, thisArg) ⇒ Promise.<undefined>
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. |
laterList/Flood.includes(toMatch, fromIndex) ⇒ Promise.<Boolean>
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. |
laterList/Flood.indexOf(toMatch) ⇒ Promise.<Number>
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. |
laterList/Flood.join(separator) ⇒ Promise.<String>
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. |
laterList/Flood.lastIndexOf(toMatch) ⇒ Promise.<Number>
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/Flood.map(lambda, thisArg) ⇒ LaterList
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. |
laterList/Flood.reduce(lambda, initialValue) ⇒ Promise.<*>
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. |
laterList/Flood.reduceRight(lambda, initialValue) ⇒ Promise.<*>
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/Flood.reverse() ⇒ LaterList
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/Flood.slice(begin, end) ⇒ LaterList
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. |
laterList/Flood.some(predicate, thisArg) ⇒ Promise.<Boolean>
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/Flood.sort(compare) ⇒ LaterList
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/Flood.splice(begin, deleteCount, ...additions) ⇒ LaterList
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/Relay ⇐ LaterList
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
laterList/Relay.length : Number
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. |
laterList/Relay.push(...values) ⇒ Number
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
laterList/Relay.consume(onData, initialValue) ⇒ Promise.<*>
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. |
laterList/Relay.value() ⇒ Promise.<Array.<*>>
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. |
laterList/Relay.when() ⇒ Promise
Resolves with undefined if the list ends without error, rejects if the list ends with an error.
Kind: instance method of LaterList/Relay
laterList/Relay.concat(...lists) ⇒ LaterList
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. |
laterList/Relay.every(predicate, thisArg) ⇒ Promise.<Boolean>
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/Relay.filter(predicate, thisArg) ⇒ LaterList
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. |
laterList/Relay.find(predicate, thisArg) ⇒ Promise.<*>
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. |
laterList/Relay.findIndex(predicate, thisArg) ⇒ Promise.<Number>
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. |
laterList/Relay.forEach(lambda, thisArg) ⇒ Promise.<undefined>
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. |
laterList/Relay.includes(toMatch, fromIndex) ⇒ Promise.<Boolean>
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. |
laterList/Relay.indexOf(toMatch) ⇒ Promise.<Number>
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. |
laterList/Relay.join(separator) ⇒ Promise.<String>
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. |
laterList/Relay.lastIndexOf(toMatch) ⇒ Promise.<Number>
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/Relay.map(lambda, thisArg) ⇒ LaterList
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. |
laterList/Relay.reduce(lambda, initialValue) ⇒ Promise.<*>
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. |
laterList/Relay.reduceRight(lambda, initialValue) ⇒ Promise.<*>
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/Relay.reverse() ⇒ LaterList
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/Relay.slice(begin, end) ⇒ LaterList
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. |
laterList/Relay.some(predicate, thisArg) ⇒ Promise.<Boolean>
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/Relay.sort(compare) ⇒ LaterList
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/Relay.splice(begin, deleteCount, ...additions) ⇒ LaterList
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
- static
- instance
laterList.length : Number
Number of nodes in the list.
Kind: instance property of LaterList
laterList.push(...values) ⇒ Number
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
laterList.consume(onData, initialValue) ⇒ Promise.<*>
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. |
laterList.value() ⇒ Promise.<Array.<*>>
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. |
laterList.when() ⇒ Promise
Resolves with undefined if the list ends without error, rejects if the list ends with an error.
Kind: instance method of LaterList
laterList.concat(...lists) ⇒ LaterList
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. |
laterList.every(predicate, thisArg) ⇒ Promise.<Boolean>
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.filter(predicate, thisArg) ⇒ LaterList
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. |
laterList.find(predicate, thisArg) ⇒ Promise.<*>
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. |
laterList.findIndex(predicate, thisArg) ⇒ Promise.<Number>
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. |
laterList.forEach(lambda, thisArg) ⇒ Promise.<undefined>
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. |
laterList.includes(toMatch, fromIndex) ⇒ Promise.<Boolean>
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. |
laterList.indexOf(toMatch) ⇒ Promise.<Number>
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. |
laterList.join(separator) ⇒ Promise.<String>
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. |
laterList.lastIndexOf(toMatch) ⇒ Promise.<Number>
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.map(lambda, thisArg) ⇒ LaterList
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. |
laterList.reduce(lambda, initialValue) ⇒ Promise.<*>
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. |
laterList.reduceRight(lambda, initialValue) ⇒ Promise.<*>
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.reverse() ⇒ LaterList
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.slice(begin, end) ⇒ LaterList
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. |
laterList.some(predicate, thisArg) ⇒ Promise.<Boolean>
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.sort(compare) ⇒ LaterList
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.splice(begin, deleteCount, ...additions) ⇒ LaterList
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. |