Recursively execute a given function where the result of each iteration is collected within a collection