| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-06-29 15:03:31 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-06-29 15:03:31 UTC |
| parent | 61d49fe918a05f7cc66036199366d126cf253e8d |
| borogove/Caps.hx | +12 | -2 |
diff --git a/borogove/Caps.hx b/borogove/Caps.hx index 81e8d88..aebb309 100644 --- a/borogove/Caps.hx +++ b/borogove/Caps.hx @@ -23,6 +23,7 @@ class Caps { private static function filter(caps:KeyValueIterator<Null<String>, Caps>, predicate:Caps->Bool):KeyValueIterator<Null<String>, Caps> { var nextMatch:Null<{key:Null<String>, value:Caps}> = null; + var initialized = false; final findNext = () -> { while (caps.hasNext()) { @@ -35,11 +36,20 @@ class Caps { nextMatch = null; }; - findNext(); + final ensureInit = () -> { + if (!initialized) { + initialized = true; + findNext(); + } + }; return { - hasNext: () -> nextMatch != null, + hasNext: () -> { + ensureInit(); + return nextMatch != null; + }, next: () -> { + ensureInit(); final r = nextMatch; if (r == null) throw "No more elements";