Skip to content

Make yield an expression, not a statement, and let the iterator provide the next value. #32831

@uehaj

Description

@uehaj
  • Dart SDK Version (dart --version)
    Dart VM version: 2.0.0-dev.32.0 (Thu Mar 1 18:39:53 2018 +0100) on "macos_x64"

Problem

In dart language, generator's yield language construct is a statement and cannot gain any value.
Although in Python and JavaScript (ES 2015), yield is a expression and can get value like:

Iterable func() sync* {
 var x = yield 33; // this is error with current Dart
}

Where the return value of yield is expected to be given from iterator side, for example:

func().moveNext("hello");  // this is an error with current Dart. moveNext cannot take parameter.

To get value from yield is extremely valuable when use generator to implement coroutine,
moreover actually it is necessarily.

I hope we can use "yield expression" in future Dart release.

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-staleClosed as the issue or PR is assumed stalecore-ntype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions