Skip to main content

Built and signed on GitHub Actions

♻️ Iterable and AsyncIterable utilities.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 weeks ago (0.3.2)
function count
count<Item>(predicate: Filter<[Item]>): (iterable: AwaitableIterable<Item>) => Promise<number>

Counts the number of items that satisfy a predicate in the given iterable or asynchronous iterable.

Examples

Example 1

const countOdds = count((number: number) => number % 2 !== 1);
countOdds([1, 2, 3, 4, 5]); // 3
countOdds([0, 2, 4, 6, 8]); // 0

Type Parameters

Item

Parameters

predicate: Filter<[Item]>

Predicate function for items to be counted.

Return Type

(iterable: AwaitableIterable<Item>) => Promise<number>

Curried function with predicate in context.

Add Package

deno add jsr:@coven/iterables

Import symbol

import { count } from "@coven/iterables/async";

---- OR ----

Import directly with a jsr specifier

import { count } from "jsr:@coven/iterables/async";

Add Package

npx jsr add @coven/iterables

Import symbol

import { count } from "@coven/iterables/async";

Add Package

yarn dlx jsr add @coven/iterables

Import symbol

import { count } from "@coven/iterables/async";

Add Package

pnpm dlx jsr add @coven/iterables

Import symbol

import { count } from "@coven/iterables/async";

Add Package

bunx jsr add @coven/iterables

Import symbol

import { count } from "@coven/iterables/async";