COMMUNITY

Which type unifies with Array, List and Map?

Hej all,

As the title suggest, I’m looking for a type that I can use in for loops.
Iterable and Iterator don’t do the job.
Let’s say I have an array and a map and I want to loop inside both.
Which type can I use for that please ? A type that says “Will be used in a for loop”

Thanks,

Why not?

Hej Jens,

Thanks for your interest.

Iterable doesn’t work for a Map and Iterator doesn’t work for an Array.

Maybe this example will be more clear : http://try-haxe.mrcdk.com/#8A162

Here with Iterable : http://try-haxe.mrcdk.com/#63bEE

Here with Iterator : http://try-haxe.mrcdk.com/#DBb91

In fact I just saw that in javascript it does work but in PHP 7 it fails once for Iterable, and once for Iterator…

But they do? This compiles fine:

var mapIterable:Iterable<String> = ["a" => "b"];
var arrayIterable:Iterable<String> = ["a"];

var mapIterator:Iterator<String> = ["a" => "b"].iterator();
var arrayIterator:Iterator<String> = ["a"].iterator();

It fails on runtime on PHP 7
(I just tested in javascript and it works fine on runtime…)

If so, that just sounds like a bug with the PHP target.

1 Like

I’ve submited an issue, I hope it’s that : https://github.com/HaxeFoundation/haxe/issues/8851

Thanks Jens :wink: