ycomb

1.0.0 • Public • Published

Y-combinator

The Y-combinator can be used to create functions that behave recursively.

// recursive factorial
let fact = n => n <= 1 ? n : n * fact(- 1)
 
// factorial using the Y-combinator
let fact = Y(f => n => n <= 1 ? n : n * f(- 1))

Read more about the Y-combinator in The Mysterious Y-combinator

Install

npm install --save ycomb

Use

import Y from 'ycomb'

Pass a function to Y that takes a function argument. Call the function argument if you want to recurse.

For an example, check out Yl, a function that behaves like a while loop (with some added benefits like currying, and return values).

License

MIT © Kevin Lanni

Package Sidebar

Install

npm i ycomb

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • therealklanni