Goes through the entire iterable, counting the values, and produces a one-value iterable with the count.
import {pipe, count} from 'iter-ops';const i = pipe( 'hello world!', count());console.log(...i); //=> 12console.log(i.first); //=> 12 Copy
import {pipe, count} from 'iter-ops';const i = pipe( 'hello world!', count());console.log(...i); //=> 12console.log(i.first); //=> 12
When the optional predicate is specified, only values that satisfy the predicate are counted.
import {pipe, count} from 'iter-ops';const i = pipe( 'hello world!', count(a => a === 'l'));console.log(...i); //=> 3console.log(i.first); //=> 3 Copy
import {pipe, count} from 'iter-ops';const i = pipe( 'hello world!', count(a => a === 'l'));console.log(...i); //=> 3console.log(i.first); //=> 3
Note that the predicate can only return a Promise inside an asynchronous pipeline, or else the Promise will be treated as a truthy value.
Promise
Optional
Goes through the entire iterable, counting the values, and produces a one-value iterable with the count.
When the optional predicate is specified, only values that satisfy the predicate are counted.
Note that the predicate can only return a
Promise
inside an asynchronous pipeline, or else thePromise
will be treated as a truthy value.