Skip to content

An abstraction over continuation-passing and trampolining to write recursive functions that don't exceed the maximum call stack size.

License

Notifications You must be signed in to change notification settings

samualtnorman/decurse

Repository files navigation

Decurse

An abstraction over continuation-passing and trampolining to write recursive functions that don't exceed the maximum call stack size.

Example

import { makeDecurse } from "decurse"

const decurse = makeDecurse()

const factorial = (/** @type {bigint} */ n) => decurse(() => n
	? factorial(n - 1n).then(result => result * n)
	: 1n
)

factorial(100_000n).then(value => console.log(value))

About

An abstraction over continuation-passing and trampolining to write recursive functions that don't exceed the maximum call stack size.

Topics

Resources

License

Stars

Watchers

Forks