2.0.1 • Published 4 years ago

variadic-y v2.0.1

Weekly downloads
45
License
MIT
Repository
-
Last release
4 years ago

variadic-y

build coverage vulnerabilities dependencies devDependencies

Variadic y-combinator for recursive anonymous functions.

Installation

npm i variadic-y

Usage

Define your recursive function to take in a reference to itself. Here, f.

import { Y } from "variadic-y";

Y(f => (x, y = 1) => (x == 1 ? y : f(x - 1, x * y)))(5); // 120

Design

Unmemoized to enable usage with objects and referentially opaque functions.

export const Y = (a: any) =>
  ((b: any) => a((...c: any[]) => b(b)(...c)))((b: any) =>
    a((...c: any[]) => b(b)(...c))
  );

If anyone knows how to properly type this combinator in TypeScript, let me know.