Skip to content

Commit

Permalink
#122: added immutable pass of stored array
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGoryunov committed Oct 5, 2021
1 parent 0a8dd4c commit 73d9dba
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/ArrayAddingIterator.php
Expand Up @@ -34,13 +34,9 @@ public function __construct(
*/
public function from(Iterator $source): AddingIterator
{
/**
* @todo #83:20min Current approach mutates existing object. If it is
* not reassigned but instead passed to some method variable which
* holds a reference to this object with be in an invalid state.
*/
$this->added[$source->key()] ??= $source->current();
return new self($this->added);
$updated = $this->added;
$updated[$source->key()] ??= $source->current();
return new self($updated);
}

/**
Expand Down

0 comments on commit 73d9dba

Please sign in to comment.