Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we generate a list with do expressions? #10

Open
kasperpeulen opened this issue Oct 11, 2017 · 4 comments
Open

Can we generate a list with do expressions? #10

kasperpeulen opened this issue Oct 11, 2017 · 4 comments

Comments

@kasperpeulen
Copy link

I was thinking about syntax like this:

<ul>
  {
    do* {
      for (let item of list) {
        yield <li>{item}</li>;
      }
    }
  }
</ul>

Or is something like this already possible?

@Jamesernator
Copy link

Jamesernator commented Oct 11, 2017

The semantics haven't been decided, I showed 3 possible options on the original gist but there's certainly other interpretations.

I'd expect though at the very least that if yield were allowed in do-expressions in some form that it would return a generator not an array, otherwise it'd be weirdly inconsistent with generator functions.

@kasperpeulen
Copy link
Author

@Jamesernator Ah interesting. I also just found this proposal:
https://github.com/sebmarkbage/ecmascript-do-generator

I would expect it to return a generator as well, but maybe JSX could automatically convert the generator to an array.

@dead-claudia
Copy link

Related: #14

@jorendorff
Copy link

You might be interested in array comprehensions, previously proposed for ECMAScript, but ultimately rejected.

Currently, this can be done using the .map() method of Array objects:

<ul>
  {
    list.map(item => <li>{item}</li>)
  }
</ul>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants