curry
Currying and partial application utilities.
Currying
Provides features related to currying.
currying is the technique of translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single argument.
curry
curry
returns curried function.
import { curry } from "https://deno.land/x/curry@$VERSION/mod.ts";
declare const fn: (a: string, b: number, c: boolean) => void;
const curriedFn = curry(fn);
curriedFn("")(0)(false);
curriedFn("", 0)(false);
curriedFn("", 0, false);
Partial application
Partial application refers to the process of fixing a number of arguments to a function, producing another function of smaller arity.
It has the following characteristics:
- The
length
property is not strict. - The
name
property isbound
.
partial
Partially applies function arguments.
import { partial } from "https://deno.land/x/curry@$VERSION/mod.ts";
declare const fn: (a: string, b: number, c: boolean) => void;
const ternary = partial(fn);
const binary = partial(fn, "");
const unary = partial(fn, "", 0);
const nullary = partial(fn, "", 0, false);
partialRight
Create right partial applied function.
import { partialRight } from "https://deno.land/x/curry@$VERSION/mod.ts";
declare const fn: (a: string, b: number, c: boolean) => void;
const binary = partialRight(fn, false);
const unary = partialRight(fn, false, 0);
const nullary = partialRight(fn, false, 0, "");
partialTail
Create tail partial applied function.
Tail is any argument other than the first argument.
import { partialTail } from "https://deno.land/x/curry@$VERSION/mod.ts";
declare const fn: (a: string, b: number, c: boolean) => void;
const binary = partialTail(fn, 0);
const unary = partialTail(fn, 0, false);
API
See deno doc for all APIs.
License
Copyright © 2023-present Tomoki Miyauchi.
Released under the MIT license