Skip to main content
ReadableBase.prototype.find - stream - Node documentation
method ReadableBase.prototype.find

Usage in Deno

import { ReadableBase } from "node:stream";
ReadableBase.prototype.find<T>(
fn: (
data: any,
options?: Pick<ArrayOptions, "signal">,
) => data is T
,
options?: ArrayOptions,
): Promise<T | undefined>

This method is similar to Array.prototype.find and calls fn on each chunk in the stream to find a chunk with a truthy value for fn. Once an fn call's awaited return value is truthy, the stream is destroyed and the promise is fulfilled with value for which fn returned a truthy value. If all of the fn calls on the chunks return a falsy value, the promise is fulfilled with undefined.

Type Parameters

T

Parameters

fn: (
data: any,
options?: Pick<ArrayOptions, "signal">,
) => data is T

a function to call on each chunk of the stream. Async or not.

optional
options: ArrayOptions

Return Type

Promise<T | undefined>

a promise evaluating to the first chunk for which fn evaluated with a truthy value, or undefined if no element was found.

ReadableBase.prototype.find(
fn: (
data: any,
options?: Pick<ArrayOptions, "signal">,
) => boolean | Promise<boolean>
,
options?: ArrayOptions,
): Promise<any>

Parameters

fn: (
data: any,
options?: Pick<ArrayOptions, "signal">,
) => boolean | Promise<boolean>
optional
options: ArrayOptions

Return Type

Promise<any>
Back to top