Skip to main content
Module

x/fun/mod.ts>option.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 option.filterMap
import { option } from "https://deno.land/x/fun@v2.0.0-alpha.12/mod.ts";
const { filterMap } = option;

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

Examples

Example 1

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

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

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>