public static function reverse<T:Dynamic, U:Dynamic>(map:Map<T, U>):Map<U, T> {
var result = new Map<U, T>();
for (key in map.keys()) {
result[map[key]] = key;
}
return result;
}
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.
The problem seems to be that Haxe compiler needs to know the real
type of a Map when creating it, and by putting it in a function
like that, it can't know the type. The trick is to create the Map
outside the function and only populate it within your function,
this does not really seem a big compromise most of the work is
still implemented in your static function and you won't get
additional runtime overheads.
public static function reversed<T,U>(map1:Map<T,
U>,map2:Map<U,T>):Map<U,T> {
for (k in map1.keys()) map2.set( map1.get(k), k );
return map2;
}
http://try-haxe.mrcdk.com/#b3B1F
Hope that helps :)
But what about '@:generic'? :D
http://try-haxe.mrcdk.com/#2CD40
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.