Allow for iterating over a collection with a callback.

This commit is contained in:
Greyscale 2021-10-26 02:36:02 +02:00
parent 5795e5c404
commit c0125706e0
No known key found for this signature in database
GPG key ID: D38CDF6CE08284DD

View file

@ -69,4 +69,13 @@ abstract class AbstractBase{{ class_name }}Collection
$this->contained[$offset] = $value;
}
public function iterate($callback, ...$callbackArguments){
foreach ($this->contained as $contained) {
$iterationArguments = $callbackArguments;
array_unshift($iterationArguments, $contained);
call_user_func_array($callback, $iterationArguments);
}
return $this;
}
}