Skip to content

V2: utils: skipWhile()

Eugene Lazutkin edited this page Aug 3, 2022 · 1 revision

(Since 2.2.0)

skipWhile() skips items as long as a function returns a truthy value, then all items are passed. It is returned by require('stream-chain/utils/skipWhile') and it is based on Transform.

Factory function: skipWhile(options)

It takes options and returns a Transform stream.

options can be one of these:

  • an object detailed in the Node's documentation.
    • readableObjectMode and writableObjectMode are always set to `true.
    • The following custom options are recognized:
      • (optional) condition is a function or an asynchronous function, which takes an item and returns a boolean. Default: () => true.
  • Otherwise it is assumed to be a function, same as condition described above.

Static property: skipWhile.Constructor

A constructor of the underlying stream class produced by skipWhile(). Useful to inspect objects with instanceof.

Static property: skipWhile.Constructor.make

An alias to skipWhile. Useful with metaprogramming.

Examples

const {chain} = require('stream-chain');
const skipWhile = require('stream-chain/utils/skipWhile');

// get numbers until we encounter 3
const pipeline = chain([
  skipWhile(item => item !== 3)
  // ... the rest of the pipeline
]);
// input:  1, 2, 3, 4, 5
// output: 3, 4, 5
Clone this wiki locally