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://raw.githubusercontent.com/baetheus/fun/main/option.ts";

Reduce over an Option. Since an Option contains at most one value this function operates a lot like getOrElse. If the passed option is None then it returns the initial value, otherwise the foldr function is called with both the initial value and the inner A.

@example
import * as O from "./option.ts";

const fold = O.fold((n: number, m: number) => n + m, 0);

const result1 = fold(O.some(1)); // 1
const result2 = fold(O.none); // 0
function fold<A, O>(foldr: (accumulator: O, current: A) => O, initial: O): (ua: Option<A>) => O;
§
fold<A, O>(foldr: (accumulator: O, current: A) => O, initial: O): (ua: Option<A>) => O
[src]

§Type Parameters

§Parameters

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

§Return Type

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