Add function to iterate over a collection