Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

flatmap

import { flatmap } from "https://raw.githubusercontent.com/baetheus/fun/main/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.

@example
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)
function flatmap<A, I>(fati: (a: A) => Option<I>): (ta: Option<A>) => Option<I>;
§
flatmap<A, I>(fati: (a: A) => Option<I>): (ta: Option<A>) => Option<I>
[src]

§Type Parameters

§Parameters

§
fati: (a: A) => Option<I>
[src]

§Return Type

§
(ta: Option<A>) => Option<I>
[src]