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://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/fn.ts";

Create a new Fn by combining A => L => I with D => A to produce D & L => I. This is equivalent to ap with the first two arguments switched. It is also limited to unary functions in order to properly handle type widening on the input type.

@example
import { pipe, flatmap } from "./fn.ts";
const add = (n: number) => (m: number) => n + m;

const flatmaper = pipe(
  (n: number) => n,
  flatmap(add),
  flatmap(add),
  flatmap(add),
  flatmap(add),
  flatmap(add),
);

const result1 = flatmaper(1); // 6
const result2 = flatmaper(2); // 12
const result3 = flatmaper(3); // 18
function flatmap<A, I, L>(fati: (a: A) => Fn<L, I>): <D>(ta: Fn<D, A>) => Fn<D & L, I>;
§
flatmap<A, I, L>(fati: (a: A) => Fn<L, I>): <D>(ta: Fn<D, A>) => Fn<D & L, I>
[src]

§Type Parameters

§Parameters

§
fati: (a: A) => Fn<L, I>
[src]

§Return Type

§
<D>(ta: Fn<D, A>) => Fn<D & L, I>
[src]