如何将打字稿中的这些过程转换为CPS格式?假设该函数在树上传递并取最左边的节点。
export const leftMostEven1 = (atree: Tree): number => {
if (isTreeLeaf(atree)){
if (atree.value%2==0)
return atree.value;
return -1;
}
else if(isTreeNode(atree)) {
for (let i =0 ; i < atree.children.length;i ++){
let a = leftMostEven1(atree.children[i]);
if (a!=-1) return a;
}
}
return -1;
}
我开始了:
const leftMostEven$ = <T1, T2>(atree: Tree,
succ: ((x:number) => T1),
fail: (() => T2)): (T1 | T2) =>
fail();