montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.1k stars 183 forks source link

Support the ES6 iteration protocol #117

Open rauschma opened 9 years ago

rauschma commented 9 years ago

Among other changes: If it is there, you should use Symbol.iterator as a property key.

Long-term, it may also make sense to rename Iterator, in order to avoid confusion with the built-in API.

Maher4Ever commented 8 years ago

Adding this to a specialized Set I have was as easy as (other code omitted for brevity):

import {Set as CollectionsSet} from 'collections/set'

class ParametersSet extends CollectionsSet {
  [Symbol.iterator]() {
    return this.iterate()
  }
}

It would be awesome to have this natively implemented in all collections though.