method StreamClass.prototype.find
Private
StreamClass.prototype.find(predicate: (
value: T,
index: number
) => boolean | PromiseLike<boolean>
): Task<T | undefined, E>

The first value satisfying predicate, or undefined — short-circuiting, so an infinite source is fine as long as a match exists.

undefined rather than a Failure for "not found": absence is an ordinary answer to a search, not a failure of the run, and Array.prototype.find sets the expectation.

await Stream.from([1, 2, 3]).find((n) => n > 1); // 2

Parameters

predicate: (
value: T,
index: number
) => boolean | PromiseLike<boolean>

Return Type

Task<T | undefined, E>

Usage

import { StreamClass } from "lib/stream/stream.ts";