Moeru AI Std
Utils

Trampoline

Use recursion and avoid stack overflow.

trampoline

Trampoline functions that accept both sync and async functions.

import type { ,  } from '@moeru/std/trampoline'

import {  } from '@moeru/std/trampoline'

const  = (: number, : number = 1): <number> =>
   <= 1
    ? 
    : () => ( - 1,  * )

const  = async (: number, : number = 1): <<number>> =>
   <= 1
    ? .()
    : async () => ( - 1,  * )

.(await (() => (5))) // 120
.(await (async () => (5))) // 120

trampolineSync

trampoline that accept only sync functions.

import type {  } from '@moeru/std/trampoline'

import {  } from '@moeru/std/trampoline'

const  = (: number, : number = 1): <number> =>
   <= 1
    ? 
    : () => ( - 1,  * )

.((() => (5))) // 120