diff --git a/std/haxe/ds/HashMap.hx b/std/haxe/ds/HashMap.hx index 4ca5e6f8f15..1e50d731990 100644 --- a/std/haxe/ds/HashMap.hx +++ b/std/haxe/ds/HashMap.hx @@ -31,7 +31,7 @@ import haxe.iterators.HashMapKeyValueIterator; @see https://haxe.org/manual/std-Map.html **/ -abstract HashMap(HashMapData) { +abstract HashMap(HashMapData) to Iterable to KeyValueIterable { /** Creates a new HashMap. **/ @@ -90,14 +90,14 @@ abstract HashMap(HashMapData) { See `Map.iterator` **/ public inline function iterator() { - return this.values.iterator(); + return this.iterator(); } /** See `Map.keyValueIterator` **/ public inline function keyValueIterator():HashMapKeyValueIterator { - return new HashMapKeyValueIterator(cast this); + return this.keyValueIterator(); } /** @@ -117,4 +117,12 @@ private class HashMapData { keys = new IntMap(); values = new IntMap(); } + + public inline function iterator() { + return values.iterator(); + } + + public inline function keyValueIterator():HashMapKeyValueIterator { + return new HashMapKeyValueIterator(cast this); + } } diff --git a/tests/unit/src/unit/TestHashMap.hx b/tests/unit/src/unit/TestHashMap.hx index 6207454ad71..34ca10300a2 100644 --- a/tests/unit/src/unit/TestHashMap.hx +++ b/tests/unit/src/unit/TestHashMap.hx @@ -2,6 +2,8 @@ package unit; import haxe.ds.HashMap; +using Lambda; + class TestHashMap extends Test { function test() { var grid = new HashMap(); @@ -24,6 +26,8 @@ class TestHashMap extends Test { asserts++; } eq(4, asserts); + + eq(4, grid.count(_ -> true)); } }