Skip to main content
Module

x/fun/mod.ts>state.flatmap

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

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>