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

Add Iterator trait and for loop #13

Open
kodek16 opened this issue May 15, 2020 · 0 comments
Open

Add Iterator trait and for loop #13

kodek16 opened this issue May 15, 2020 · 0 comments

Comments

@kodek16
Copy link
Owner

kodek16 commented May 15, 2020

Add a trait named Iterator that enables iteration over arbitrary sequences. Also consider adding Iterable trait to be implemented by collections with a single iter method that returns a new Iterator.

As the main consumer of these traits, add a for loop syntax. for loops require an Iterable value. They create a new variable visible inside the loop body that takes on consequent values returned by the created Iterator.

The syntax for for loops could look like this:

var v = [1, 2, 3];
for (x in v) {
  writeln x;
}

v must implement Iterable, and the type of x is inferred from this implementation.

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