-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
질문있습니다~
22.06.05 18:43 작성 조회수 149
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
유인동
지식공유자2022.06.05
https://github.com/marpple/FxJS/blob/master/Strict/reduce.js
강의에서 추후 while로 변경한 것으로 기억합니다 :)
답변 1