Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

fold

import { fold } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/async_iterable.ts";

Fold over an AsyncIterable to produce a single value.

@example
import { fold } from "./async_iterable.ts";
import { fromIterable } from "./async_iterable.ts";
import { pipe } from "./fn.ts";

const numbers = fromIterable([1, 2, 3, 4, 5]);
const sum = await pipe(
  numbers,
  fold((acc, value) => acc + value, 0)
);

console.log(sum); // 15
function fold<A, O>(foldr: (
value: O,
accumulator: A,
index: number,
) => O
, initial: O): (ta: AsyncIterable<A>) => Promise<O>;
§
fold<A, O>(foldr: (value: O, accumulator: A, index: number) => O, initial: O): (ta: AsyncIterable<A>) => Promise<O>
[src]

§Type Parameters

§Parameters

§
foldr: (value: O, accumulator: A, index: number) => O
[src]
§
initial: O
[src]

§Return Type

§
(ta: AsyncIterable<A>) => Promise<O>
[src]