most-nth
Retrieves the event at ordinal index n
from a most.js stream as a Promise
. If n
is negative (and the stream finishes), the nth element from the end is returned.
Installation
Using npm:
$ npm install --save most-nth
In Node.js:
const nth first last = ;
Usage
nth
stream.thru(nth(index)) -> Promise
stream: -a--b--c----d-->
stream.thru(nth(2)): c
first
stream.thru(first) -> Promise
stream: -a--b--c----d-->
stream.thru(first): a
last
stream.thru(last) -> Promise
stream: -a--b--c--d--|
stream.thru(last): d
Examples
const most = ;const nth = ; // Logs// 4most // 9 first numbers // Retrieve the event at index 4
const most = ;const nth = ; // Logs// 7most // 9 first numbers // Retrieve the 2nd event from the end
const most = ;const first = ; // Logs// 0most // 9 first numbers // Retrieve the first event
const most = ;const last = ; // Logs// 8most // 9 first numbers // Retrieve the last event