Proposal: for-of-withas a way to provide a value to the generator

Isiah Meadows isiahmeadows at
Tue Aug 22 06:40:23 UTC 2017

To be honest, I'm not too sold on either of these:

1. The `with <expr>` reads like an expression evaluated *only once*.

2. The `continue with <expr>` does not provide a way to send a value on the
first `next` call.

One idea is to use a glorified reducer, like this (simplified):
function pipe(gen, start, func) {
    var iter = gen[Symbol.iterator]()
    var current =
    while (!current.done) {
        start = func(current.value)
        current =
    return current.value

But even that has its limits (inability to recover from errors, for
example), and it's a pretty inelegant solution to this IMHO.

In general, if you find yourself using iterators like that, `for ... of` is
quite possibly the most way to use them. Think of them as sync send/receive
channels, where you send the argument, block during processing, and receive
through the return value. Here's how you should be using them, if you must:

var fibs = fibonacci()
var result =

while (!result.done) {
    result =

On Mon, Aug 21, 2017, 22:04 jong chan moe <jong at> wrote:

> I think it would be natural to use it with the `continue` statement.
> ```js
> for (let value of fibonacci()) {
>    console.log(value);
>    continue with value == 8;
> }
> ```
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list