feat(util/list_fn): add iter function
This commit is contained in:
parent
15979ab991
commit
1a3ea26032
1 changed files with 13 additions and 0 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue