laterlist

1.0.1 • Public • Published

LaterList Build Status

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.

  • 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/FloodLaterList

A Flood is a LaterList for which values are processed immediately.

LaterList/RelayLaterList

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/Flood ⇐ [LaterList](#LaterList) A Flood is a LaterList for which values are processed immediately.

Kind: global class
Extends: 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.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.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.

Package Sidebar

Install

npm i laterlist

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • will-weiss