mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
2ead3746d6
commit
6c136c9cf2
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user