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

Better support for ES6 Iterators #68

Closed
leebyron opened this issue Aug 15, 2014 · 11 comments
Closed

Better support for ES6 Iterators #68

leebyron opened this issue Aug 15, 2014 · 11 comments

Comments

@leebyron
Copy link
Collaborator Author

0164a55 Adds Iterator methods to Vector, Map, Set, OrderedMap

@leebyron
Copy link
Collaborator Author

049eff1 Adds ES6 Symbol.iterator polyfill

@jsilvestre
Copy link

Hi,

I'm not sure it's the right place to ask/tell but I've tried to use orderedMap.values() but the result does not seem to have a done property nor next() method. Is it a bug or am I just misusing it?

Thanks.

@leebyron
Copy link
Collaborator Author

Hey Joseph, what version are you using?—
Sent from Mailbox

On Fri, Aug 29, 2014 at 1:51 AM, Joseph Silvestre
notifications@github.com wrote:

Hi,
I'm not sure it's the right place to ask/tell but I've tried to use orderedMap.values() but the result does not seem to have a done property nor next() method. Is it a bug or am I just misusing it?

Thanks.

Reply to this email directly or view it on GitHub:
#68 (comment)

@jsilvestre
Copy link

Sorry, I've tried the latest one, 2.0.16

@voodoohop
Copy link

is there any way to create a lazy Sequence directly from an ES6 generator?

@leebyron
Copy link
Collaborator Author

Not yet, but I have that on my short list!—
Sent from Mailbox

On Mon, Sep 22, 2014 at 8:54 PM, voodoohop notifications@github.com
wrote:

is there any way to create a lazy Sequence directly from an ES6 generator?

Reply to this email directly or view it on GitHub:
#68 (comment)

@leebyron
Copy link
Collaborator Author

As of v2.3.0, all Sequences can be iterated and all collections can be constructed from an Iterator or Iterable.

@magnushiie
Copy link

Should the typings of Iterable<K, V> be updated to include the method?

[Symbol.iterator](): Iterator<T>;

I'm not sure this is the right way for 2 reasons:

  • The Symbol symbol is declared only for TypeScript ES6 target - for backwards compatibility, should SymbolConstructor and Symbol be defined in immutable.d.ts also?
  • From source it seems KeyedIterable returns entries() instead of values(), so the type of it is different. Maybe it's enough to override the iterable method in Iterable.Keyed to return the appropriate type instead.

@samwgoldman
Copy link
Contributor

From source it seems KeyedIterable returns entries() instead of values()

You hit the nail on the head here. This is the real issue with making the base class iterable. Consider the following function:

function f(iter: Iterable<A,B>): Array<?> {
  out = [];
  for (let x of iter) {
    out.push(x);
  }
  return out;
}

What type belongs in ?? If I pass a KeyedIterable, it would be [K,V], if I pass anything else, it would be V.

@magnushiie
Copy link

It seems then that Immutable.Iterable itself should not be Iterable in the ES6 sense (as defined in lib.core.es6.d.ts), because its type is ill-defined. Instead, Iterable.Indexed and Iterable.Keyed should be ES6-iterable. It's bit of a pain because the Iterable methods like map aren't typed as returning this, but it would still be better than nothing.

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

No branches or pull requests

5 participants