feat(util/list_fn): add iter function

This commit is contained in:
Soonho Kong 2013-10-01 00:18:55 -07:00
parent 15979ab991
commit 1a3ea26032

View file

@ -115,6 +115,19 @@ list<T> map(list<T> const & l, F f) {
}
}
/**
\brief Given list <tt>(a_0, ..., a_k)</tt>, exec f(a_0); f(a_1); ... f(a_k)</tt>.
*/
template<typename T, typename F>
void iter(list<T> const & l, F f) {
if (is_nil(l)) {
return;
} else {
f(head(l));
return iter(tail(l), f);
}
}
/**
\brief Compare two lists using the binary predicate p.
*/