Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>promise.flatmap

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

Create a new Promise by flatmaping over the result of an existing Promise. This is effectively Promise.then.

Examples

Example 1

import { wrap, flatmap } from "./promise.ts";
import { pipe } from "./fn.ts";

const result = await pipe(
  wrap(1),
  flatmap(n => wrap(n + 1)),
); // 2

Parameters

faui: (a: A) => Promise<I>

Returns

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