variadic-y

2.0.1 • Public • Published

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.

Package Sidebar

Install

npm i variadic-y

Weekly Downloads

52,939

Version

2.0.1

License

MIT

Unpacked Size

5.16 kB

Total Files

12

Last publish

Collaborators

  • mpoteat