Skip to content

feat: multiple appended/prepended items#214

Draft
gp-lnuff wants to merge 2 commits into
CodeWithDennis:4.xfrom
gp-lnuff:generators
Draft

feat: multiple appended/prepended items#214
gp-lnuff wants to merge 2 commits into
CodeWithDennis:4.xfrom
gp-lnuff:generators

Conversation

@gp-lnuff
Copy link
Copy Markdown
Contributor

Currently, append() and prepend() accept an array or Closure to append/prepend one item to the tree.

This limitation is due to two factors:

  • Previously in those same functions, and more recently in getAppendedItems() and getPrependedItems(), there is a hard check for 'value' and 'name' keys in the supplied array or the array the Closure is expected to resolve to.

  • Collection's prepend method expects exactly one $value, and push's ...$value is a variadic parameter, so passing a nested array to it would break the structure of the tree.

The solution is to use Generators:

  • two new protected methods, generatePrependedItems() and generateAppendedItems() have been added, to yield multiple tree elements from $this->prepend and $this->append, be they an array or a Closure.

  • in getTree(), by using unshift() instead of prepend(), multiple values can be prepended. By using the ... unpacking operator on the new Generators, the values are yielded and fed into the methods like a variadic parameter.

  • the logic in getAppendedItems() and getPrependedItems() has been deferred to the Generators, and those helpers now fetch the resolved items from them.

Naturally, this change is strictly an enhancement and does not introduce regressions to my knowledge (local manual testing), single-item append/prepend is handled as it has been.

This PR needs to:

  • merge the latest upstream PR

  • update documentation

I'd move along with those two points if the feature is greenlit.

@gp-lnuff gp-lnuff marked this pull request as draft May 22, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant