Logo

Programming-Idioms

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

Idiom #242 Iterate over a set

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

(doseq [e x]
  (f e))
#include <algorithm>
std::for_each(x.begin(), x.end(), f);
for (auto e : x)
    f(e);
foreach(var e in x)
    f(e);
x.forEach(f);
for e := range x {
	f(e)
}
x.forEach(f);
let v = x.values();
let result = v.next();
while (!result.done) {
  f(result.value);
  result = v.next();
}
for (const e of x) {
	f(e);
}
import java.util.Set;
for(T e: x) {
  f(e);
}
for e in x do f(e);
f($_) for @x;
for e in x:
    f(e)
list(map(lambda e: f(e), x))
x.each { |e| f(e) }
use std::collections::HashSet;
for item in &x {
    f(item);
}

New implementation...