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

x/fun/mod.ts>promise.apply

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

Create a new Promise from a Promise<(a: A) => I> and a Promise. Although Promises encapsulate asynchrony, there is no way defer a Promise once created, thus this ap function always evaluates both input Promises in parallel.

Examples

Example 1

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

type Person = { name: string, age: number };

const person = (name: string) => (age: number): Person => ({ name, age });

const result = pipe(
  wrap(person),
  apply(wrap("Brandon")),
  apply(wrap(37)),
); // Promise<Person>

Parameters

ua: Promise<A>

Returns

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