Skip to main content
Module

x/ahh/mod.ts>Iterator#fold

Opinionated idiomatic features for TypeScript.
Go to Latest
method Iterator.prototype.fold
import { Iterator } from "https://deno.land/x/ahh@v0.13.0/mod.ts";

Consumes this and calls fn on each item to collect them into init.

Examples

Example 1

import { assert } from "../test_deps.ts";
import I from "./iterator.ts";

const sum = (a: number, b: number): number => a + b;
const iter = I.fromIter([1, 2, 3]);

assert(iter.fold(0, sum) === 6);

Parameters

init: U
fn: (init: U, item: T) => U