generalized for_each