Skip to main content
Module

x/fun/option.ts>flatmap

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function flatmap
import { flatmap } from "https://deno.land/x/fun@v2.0.0/option.ts";

Apply a function (a: A) => Option to the wrapped value of an Option if the wrapped value exists, flattening the application result into an Option. This is the equivalent of first mapping from Option to Option<Option> and then calling join to flatten the Options.

Examples

Example 1

import * as O from "./option.ts";
import { pipe } from "./fn.ts";

const result = pipe(
  O.some(1),
  O.flatmap(n => n > 0 ? O.some(n) : O.none),
); // Some(1)

Parameters

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

Returns

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