NEW: Iterate ArrayList via a generator

Using a generator here means that we don’t need to prepare a duplicate
array in-memory before iterating.
This commit is contained in:
Sam Minnee 2017-01-17 12:52:14 +13:00 committed by Guy Sartorelli
parent 2ead3746d6
commit 6c136c9cf2
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A

View File

@ -109,13 +109,13 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
#[\ReturnTypeWillChange]
public function getIterator()
{
$items = array_map(
function ($item) {
return is_array($item) ? new ArrayData($item) : $item;
},
$this->items ?? []
);
return new ArrayIterator($items);
foreach ($this->items as $i => $item) {
if (is_array($item)) {
yield new ArrayData($item);
} else {
yield $item;
}
}
}
/**