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

Guaranteed break with #1649

Open
edemaine opened this issue Dec 18, 2024 · 0 comments
Open

Guaranteed break with #1649

edemaine opened this issue Dec 18, 2024 · 0 comments

Comments

@edemaine
Copy link
Collaborator

edemaine commented Dec 18, 2024

This seems like a useful construction, analogous to Array.prototype.find:

result := for x of y when condition(x)
  break with x

The generated code

let results;results=[];for (const x of y) {if (!condition(x)) continue;
  results = x;break
};const result =results

sets results = []. It would type better without that. We can detect this by seeing that the loop always exits.


Related, I wonder if there should be a reducer for this, called for find or for first. It's similar to for some but returning the first item instead of a boolean.

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

1 participant