UNPKG

ts-tco

Version:

Utility for flattening tail recursion in TypeScript

18 lines (17 loc) 645 B
export declare const executeTco: <T>(v: TcoLike<T>) => T; export declare class Tco<T> { func: TcoFunc<T>; constructor(func: TcoFunc<T>); execute(): T; then<U>(func: (val: T) => TcoLike<U>): TcoThen<T, U>; } export declare class TcoThen<T, U> { from: TcoLike<T>; func: (val: T) => TcoLike<U>; constructor(from: TcoLike<T>, func: (val: T) => TcoLike<U>); execute(): U; then<V>(func: (val: U) => TcoLike<V>): TcoThen<U, V>; } export declare type TcoLike<T> = T | Tco<T> | TcoThen<any, T>; export declare type TcoFunc<T> = () => TcoLike<T>; export declare const tco: <T extends unknown>(f: TcoFunc<T>) => Tco<T>;