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

IntIterators are not Iterable #11664

Open
kaug-whis opened this issue May 10, 2024 · 4 comments
Open

IntIterators are not Iterable #11664

kaug-whis opened this issue May 10, 2024 · 4 comments

Comments

@kaug-whis
Copy link

kaug-whis commented May 10, 2024

using Lambda;
...
(1...3).iter(i->trace(i));

The above seems like it should be valid syntax, but since IntIterator does not have an iterator():Iterator<Int> method to allow it to work as an Iterable, it does not work.

@Simn
Copy link
Member

Simn commented May 10, 2024

The real problem here is that Lambda works with Iterable, not Iterator. That's where this issue should be addressed, but I don't know how exactly to do that.

@Apprentice-Alchemist
Copy link
Contributor

Making Lambda work with both would be relatively simple, for example using an abstract with implicit conversions from both Iterable and Iterator: https://try.haxe.org/#8e6b3e3d

@Simn
Copy link
Member

Simn commented May 11, 2024

Huh, I thought we disallowed the combination of static extensions and implicit casts, but I guess I'm thinking of something else.

@kLabz
Copy link
Contributor

kLabz commented May 11, 2024

Right, it doesn't work with [0,1,2].iter(item -> trace(item));

And this looks silly 😅

overload extern inline function iter<T>(it:Iterable<T>, fn:T->Void) {
	for (item in it)
		fn(item);
}

overload extern inline function iter<T>(it:Iterator<T>, fn:T->Void) {
	for (item in it)
		fn(item);
}

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

Successfully merging a pull request may close this issue.

4 participants