Похожие чаты

But never on generators? Or I just don't read enough

about them

4 ответов

15 просмотров

Yeah, internally they're using generators and yield.

Iterators and generators have the same functionality. So I thought.

I think you can (sort of?) fake a generator...but I'm not entirely sure. The idea is that you can pause the generator function where it yields and it can send a value out, and the caller can send a value back in if it wants.

I imagine this would be difficult to implement with an iterator function* foo(x) { if (x === 42) return true; let y; while (x <= 0) { y = yield x++; } while (y >= 0) { x = yield y--; } return x === y; }

Похожие вопросы

Обсуждают сегодня

Карта сайта