/** * @tsplus type ChainRec */ export interface ChainRec extends HKT.Typeclass { readonly Law: { readonly ChainRec: "ChainRec" } readonly chainRec: ( f: (a: A) => HKT.Kind> ) => (a: A) => HKT.Kind } /** * @tsplus type ChainRec/Ops */ export interface ChainRecOps {} export const ChainRec: ChainRecOps = {} /** * @tsplus static ChainRec/Ops tailRec */ export function tailRec(a: A, f: (a: A) => Either): B { let v = f(a) while (v._tag === "Left") { v = f(v.left) } return v.right }