Skip to content
New issue

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

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

Already on GitHub? # to your account

Make the underscore wrapper iterable #2447

Open
jdalton opened this issue Feb 27, 2016 · 1 comment
Open

Make the underscore wrapper iterable #2447

jdalton opened this issue Feb 27, 2016 · 1 comment

Comments

@jdalton
Copy link
Contributor

jdalton commented Feb 27, 2016

Thoughts on making the Underscore wrapper an iterator and iterable?

It would require detecting Symbol.iterator and doing something like

_.prototype[Symbol.iterator] = function() {
  return this;
};
_.prototype.next = function() {
  if (this.__values__ === undefined) {
    this.__values__ = _.toArray(this.value());
  }
  var done = this.__index__ >= this.__values__.length,
      value = done ? undefined : this.__values__[this.__index__++];
  return { 'done': done, 'value': value };
};

Related to jashkenas/backbone#3954 (comment).

@jgonggrijp jgonggrijp changed the title iterator support Make the underscore wrapper iterable May 9, 2020
@jgonggrijp
Copy link
Collaborator

Should only be implemented if #2147 is implemented, too. In addition, I disagree with the above code example as it would be possible to iterate the wrapper only once, despite the fact that the underlying values are not really consumed.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants