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/iterable.ts";

Fold an Iterable into a single value using a reducer function and initial value.

@example
import * as I from "./iterable.ts";

const numbers = I.wrap(1, 2, 3, 4, 5);
const sum = I.fold((acc: number, n: number) => acc + n, 0)(numbers);
// 15

const concatenated = I.fold(
  (acc: string, s: string) => acc + s,
  ""
)(I.wrap("hello", " ", "world"));
// "hello world"
function fold<A, O>(foldr: (accumulator: O, value: A) => O, initial: O): (ua: Iterable<A>) => O;
§
fold<A, O>(foldr: (accumulator: O, value: A) => O, initial: O): (ua: Iterable<A>) => O
[src]

§Type Parameters

§Parameters

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

§Return Type

§
(ua: Iterable<A>) => O
[src]