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

x/fun/state.ts>flatmap

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

Pass the A value in a State<S, A> into a function (a: A) => State<S, I>. This results in a new State<S, I>.

Examples

Example 1

import * as S from "./state.ts";
import { pipe } from "./fn.ts";

const state = pipe(
  S.id<number>(),
  S.flatmap(n => S.wrap(n + 1)),
);

const result1 = state(1); // [2, 1]
const result2 = state(2); // [3, 2]

Parameters

fati: (a: A) => State<E, I>

Returns

(ta: State<E, A>) => State<E, I>