implement for_each