iterators
iterators copied to clipboard
Add `RecursiveIterableAggregate`
Hello,
First, I'd like to say: great library you have here!
I was hoping to contribute by adding RecursiveIterableAggregate for traversing tree-like structures, but I didn't check the open pull requests first and, ironically, found a very similar PR already in progress. Since the work I've done isn't much, feel free to discard this PR if you find it unnecessary.
I’m not sure if the class name is correct, but I’ve tried to find inspiration in MapIterableAggregate and model this class similarly. I’ve also aimed to pass the callback arguments in the same way that MapIterableAggregate does (i.e., passing value, key, and the original iterable).
PR Summary
-
Introduction of New Class We've introduced a new class called
RecursiveIterableAggregate. This class complies withIteratorAggregate, a standard set of rules for creating objects that can be looped through - or "iterated" - in a particular fashion. -
Nesting and Flattening Capabilities The new class constructor is now able to take an iterable (a data structure that can be looped through) and a specific criteria - represented as a closure - that's utilized to streamline or 'flatten' nested data structures. This simplifies complex data for more efficient processing.
-
Iterate with Efficiency We've developed the
getIteratormethod. This allows for iterative access - allowing us to go through data piece by piece - to yield or output the flattened data from the supplied iterable. -
Added Recursive Flattening A private method
flattenhas been added. This method is designed to recursively flatten iterable data based on the provided closure logic. -
Testing the New Class A new test class named
RecursiveIterableAggregateTesthas been created to ensure theRecursiveIterableAggregateclass functions as expected. -
Test Data Provider We've included a method
provideBasicCasesin our test class. This method offers sets of input and corresponding expected output for testing elementary cases. -
Test Execution The
testBasicmethod has been implemented to test basic use cases. It asserts or verifies that the expected results match the output from theRecursiveIterableAggregateiterable process.
The code LGTM, nothing to add any more.
I am glad I could help.
So sad we had to add so many things when it can be replaced with a single line and recursion... but this is how it is in PHP.
Yeah but that's why we have encapsulation:) You made a good point about performance.
The only missing thing is the documentation in the README file, if you could add an entry in there, it would be really nice.
I am on it.
Thank you for the nice review BTW!
Thank you <3 !