Skip to main content
Module

x/fun/mod.ts>option.reduce

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function option.reduce
import { option } from "https://deno.land/x/fun@v.2.0.0-alpha.11/mod.ts";
const { reduce } = option;

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 reducer function is called with both the initial value and the inner A.

Examples

Example 1

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

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

const result1 = reduce(O.some(1)); // 1
const result2 = reduce(O.none); // 0

Parameters

reducer: (accumulator: O, current: A) => O
initial: O

Returns

(ua: Option<A>) => O