Skip to main content
Module

x/fun/mod.ts>fn.Fn

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

A Fn, also known as Reader or Environment, is a type over a unary javascript function. ie. (a: number) => string can be a Fn. As an algebraic data type, the associated type class instances for Fn are limited to single variable inputs so they will look like (a: number) => string, with only one argument. The purposes of a Fn are many and varied, some common purposes are: computation, reading values from a shared environment, and sub-computations in a modified environment. In many ways Fn is a more powerful abstraction than State, and indeed the State monad in fun is exactly State<S, A> = Fn<[S], [A, S]>.

Currently, there is no implementation of Chain recursion or trampolining for Fn implemented, but it is likely to be a future feature. Once implemented Fn will gain some much needed stack safety.

definition: (d: D) => A