Open kaug-whis opened 1 month ago
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.
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
Huh, I thought we disallowed the combination of static extensions and implicit casts, but I guess I'm thinking of something else.
Right, it doesn't work with [0,1,2].iter(item -> trace(item));
And this looks silly :sweat_smile:
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);
}
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.