Skip to main content
Module

x/fun/option.ts>filterMap

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 filterMap
import { filterMap } from "https://deno.land/x/fun@v.2.0.0-alpha.11/option.ts";

Apply a filter and mapping operation at the same time against an Option. This is equivalent to the chain function for Option.

Examples

Example 1

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

const nonempty = (str: string) => str.length > 0 ? O.some(str.length) : O.none;
const filterMap = O.filterMap(nonempty);

const result1 = filterMap(O.some("Hello")); // Some(5);
const result2 = filterMap(O.some("")); // None
const result3 = filterMap(O.none); // None

Parameters

fai: (a: A) => Option<I>

Returns

(ua: Option<A>) => Option<I>