curry

deno land deno doc GitHub release (latest by date) codecov GitHub

test NPM

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: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 is bound.

papplyLeft

curry:papplyLeft

Create a bound function with arguments fixed from the left.

import { papplyLeft } from "https://deno.land/x/curry@$VERSION/mod.ts";

declare const fn: (a: string, b: number, c: boolean) => void;

const ternary = papplyLeft(fn);
const binary = papplyLeft(fn, "");
const unary = papplyLeft(fn, "", 0);
const nullary = papplyLeft(fn, "", 0, false);

papplyRight

curry:partialRight

Create a bound function with arguments fixed from the right

import { papplyRight } from "https://deno.land/x/curry@$VERSION/mod.ts";

declare const fn: (a: string, b: number, c: boolean) => void;

const binary = papplyRight(fn, false);
const unary = papplyRight(fn, false, 0);
const nullary = papplyRight(fn, false, 0, "");

papplyRest

curry:papplyRest

Create a bound function with fixed arguments except the first one.

import { papplyRest } from "https://deno.land/x/curry@$VERSION/mod.ts";

declare const fn: (a: string, b: number, c: boolean) => void;

const binary = papplyRest(fn, 0);
const unary = papplyRest(fn, 0, false);

API

See deno doc for all APIs.

License

Copyright © 2023-present Tomoki Miyauchi.

Released under the MIT license