-
-
Notifications
You must be signed in to change notification settings - Fork 11
V2: utils: takeWhile()
Eugene Lazutkin edited this page Aug 3, 2022
·
1 revision
(Since 2.2.0)
takeWhile()
takes items as long as a function returns a truthy value, then all items are ignored. It is returned by require('stream-chain/utils/takeWhile')
and it is based on Transform.
It takes options
and returns a Transform stream.
options
can be one of these:
- an object detailed in the Node's documentation.
-
readableObjectMode
andwritableObjectMode
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
.
-
(optional)
-
- Otherwise it is assumed to be a function, same as
condition
described above.
A constructor of the underlying stream class produced by takeWhile()
. Useful to inspect objects with instanceof
.
An alias to takeWhile
. Useful with metaprogramming.
const {chain} = require('stream-chain');
const takeWhile = require('stream-chain/utils/takeWhile');
// get numbers until we encounter 3
const pipeline = chain([
takeWhile(item => item !== 3)
// ... the rest of the pipeline
]);
// input: 1, 2, 3, 4, 5
// output: 1, 2