import { BaseGenerator, IScope } from '../types/core'; export function executeFunctionStack( input: I, scope: IScope, funcs: BaseGenerator | Array>, baseFunc: BaseGenerator, config?: C, ): T { const funcList: Array> = []; if (Array.isArray(funcs)) { funcList.push(...funcs); } else { funcList.push(funcs); } let next: BaseGenerator = baseFunc; while (funcList.length > 0) { const func = funcList.pop(); if (func) { const warppedFunc = ((nextFunc) => (i: I, s: IScope, cfg?: C) => func(i, s, cfg, nextFunc))(next); next = warppedFunc; } } return next(input, scope, config); }