인프런 커뮤니티 질문&답변
질문있습니다~
작성
·
232
0
const reduce = curry((f, acc, iter) => {
if (!iter) {
iter = acc[Symbol.iterator]();
acc = iter.next().value;
}
return go1(acc, function recur(acc) {
for (const el of iter) { ////////////////////////////////???????
acc = f(acc, el);
console.log(acc);
if (acc instanceof Promise)
return acc.then((res) => {
console.log(res);
recur(res);
});
}
return acc;
});
})
for of문을 돌리다 중간에 흐름이 멈추면 강제로 generator return 메서드를 사용해 흐름이 끊기게 되는데,
여기서는 어떻게 acc.then에서 다시 recur(res)를 할 때 멈춘시점의 iter의 값을 기억할 수 있는 걸까요?
https://www.inflearn.com/questions/17067 의 내용은 이미 확인한 상태입니다.
답변 1
1
MDU 유인동
지식공유자
https://github.com/marpple/FxJS/blob/master/Strict/reduce.js
강의에서 추후 while로 변경한 것으로 기억합니다 :)






넵..! 그런데 for of 로 순회를 해도 정상적으로 작동되는게 이상해서 질문드렸습니다 ㅎㅎ..