Skip to main content
Module

x/fun/mod.ts>promise.map

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

Create a new Promise by mapping over the result of an existing Promise. This is effectively Promise.then, but narrowed to non-promise returning functions. If the mapping function returns a Promise then the type for this function will be incorrect, as there is no way to create a Promise<Promise>.

Examples

Example 1

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

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

Parameters

fai: (a: A) => I

Returns

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