Taxonomy's TermStorage::loadTree method processes trees using a loop instead of recursion. It would be nice to have a generic form of this solution that could be used for any nested array.
The attached patch adds a process() method to the NestedArray class that enables it to run callables on the elements of a nested array without using recursion.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.