Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Js

Idiom #242 Iterate over a set

Call a function f on each element e of a set x.

for (const e of x) {
	f(e);
}
x.forEach(f);

x has type Set
let v = x.values();
let result = v.next();
while (!result.done) {
  f(result.value);
  result = v.next();
}

For old JS standards that don't support for...of.
(doseq [e x]
  (f e))

New implementation...