foreach_function util function