Iteration protocol: a sentinel value?

Axel Rauschmayer axel at rauschma.de
Tue May 14 05:51:56 PDT 2013


I’m guessing that the semantics are not negotiable, but if they were, I would let an empty `return` terminate the generator, while

    return expr;

would be synonymous to

    yield expr;
    return;

That would more clearly separate concerns – I’m not too fond of the stopping mechanism (be it {done} or StopIteration) having to play double duty.

On May 14, 2013, at 13:46 , André Bargull <andre.bargull at udo.edu> wrote:

> `return <expression>` is allowed within a generator [1] and to be able to retrieve the <expression>'s value, a (possibly frozen) sentinel value doesn't quite work.
> 
> A simple example:
> 
> function* gen() {
>  return 123;
> }
> 
> var {value, done} = gen().next();
> assertEq(done, true);
> assertEq(value, 123);
> 
> 
> [1] http://wiki.ecmascript.org/doku.php?id=harmony:generators#returning

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130514/f9701dfb/attachment.html>


More information about the es-discuss mailing list