git » sdk » commit f7e77ee

borogove.Map to iterable

author Eric Roberts
2026-10-14 15:39:35 UTC
committer Eric Roberts
2026-10-14 15:46:20 UTC
parent 9667f71147f22c611fb5d688bd131b9f4f2f212a

borogove.Map to iterable

So that I can do Lambda.array(someMap) and it works like I want it to.

borogove/Map.js.hx +4 -0
test/TestUtil.hx +14 -0

diff --git a/borogove/Map.js.hx b/borogove/Map.js.hx
index de209aa..69fd97e 100644
--- a/borogove/Map.js.hx
+++ b/borogove/Map.js.hx
@@ -36,6 +36,10 @@ abstract Map<K,V>(NativeMap<K,V>) {
 		return new HaxeIterator(this.values());
 	}
 
+	@:to public inline function toIterable():Iterable<V> {
+		return { iterator: iterator };
+	}
+
 	public inline function map<B>(f: V->B):Array<B> {
 		return [for (x in this) f(x)];
 	}
diff --git a/test/TestUtil.hx b/test/TestUtil.hx
index c3bcd44..bfeba44 100644
--- a/test/TestUtil.hx
+++ b/test/TestUtil.hx
@@ -2,8 +2,22 @@ package test;
 
 import utest.Assert;
 import borogove.Util;
+#if js
+import borogove.Map;
+#end
 
 class TestUtil extends utest.Test {
+	public function testMapAsIterable() {
+		final map = new Map<String, Int>();
+		Assert.same([], Lambda.array(map));
+
+		map.set("first", 1);
+		map.set("second", 2);
+		final array = Lambda.array(map);
+		array.sort(Reflect.compare);
+		Assert.same([1, 2], array);
+	}
+
 	public function testXmlEscape() {
 		Assert.equals("foo &amp; bar &lt; baz &gt;", borogove.Util.xmlEscape("foo & bar < baz >"));
 		Assert.equals("nothing", borogove.Util.xmlEscape("nothing"));