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

Proposal: Symbol.breakLoop for exit from forEach loops #41

Closed
xlaywan opened this Issue May 30, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@xlaywan

xlaywan commented May 30, 2015

Now there is no way to exit from forEach loops.

iterable.forEach(item => {
  if (item == 'what we need')
    return Symbol.breakLoop // loop breaks here
})

Traditional equivalent

for (let item of iterable) {
  if (item == 'what we need')
    break
}

Or just Symbol.break.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost May 30, 2015

What's wrong with using .some / .every and using return true / return false to break out?

ghost commented May 30, 2015

What's wrong with using .some / .every and using return true / return false to break out?

@xlaywan

This comment has been minimized.

Show comment
Hide comment
@xlaywan

xlaywan May 30, 2015

Oh, sure, forgot them) Issue can be closed.

xlaywan commented May 30, 2015

Oh, sure, forgot them) Issue can be closed.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb May 30, 2015

Member

Also ES6's Array#find will return the item you're looking for, or undefined, stopping the iteration as soon as the predicate returns true.

Member

ljharb commented May 30, 2015

Also ES6's Array#find will return the item you're looking for, or undefined, stopping the iteration as soon as the predicate returns true.

@bterlson bterlson closed this Sep 22, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment