ts-tco

Utility for flattening tail recursion in TypeScript

Usage no npm install needed!

<script type="module">
  import tsTco from 'https://cdn.skypack.dev/ts-tco';
</script>

README

ts-tco

Utility for flattening tail recursion in TypeScript

Usage

import { Tco, tco } from "ts-tco";

const countUp = (n: number, total = 0): Tco<number> => tco(() => {
  if (n === 0)
    return total;

  return countUp(n - 1, total + 1);
})

console.log(countUp(2000000).execute()); // 2000000