-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursive iteration #36
Conversation
I like (and need) this. How is this going? Can I help? Thanks |
Thank you. No progress whatsoever :) The idea persists though. |
Could a nested JSON pointer - as explained in the readme - help you in the meantime? |
I tried to implement it and turned this Issue into PR. Can you try it and throw in some suggestions? |
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #36 +/- ##
=============================================
- Coverage 100.00% 99.67% -0.33%
- Complexity 185 220 +35
=============================================
Files 17 19 +2
Lines 526 607 +81
=============================================
+ Hits 526 605 +79
- Misses 0 2 +2 ☔ View full report in Codecov by Sentry. |
I ponder that a better name for this feature might be something like |
Hey @halaxa, I was looking into a very similar solution a couple of days ago. Great timing! I'd say that what we are leveraging here are technically nested iterators, so probably naming them as what they actually are may cause less confusion. I see that you generate iterators for objects too, wouldn't iterators for arrays be enough? |
I agree that recursive is not the right word to use. As @cerbero90 suggested, nested iterator would make sense. Also, by returning an actual Iterator object it would be possible to use SPL iterators to further filter the data. |
So the name of the feature and the option would be nested iterators? The point about not iteratig objects made me think of two optinons instead of just one. One for arrays as iterators and second for objects as iterators. That way users can decide what they want. Also, what about providing a method called for example The nested iterator should also be |
Looking at the recursive example in the readme in this PR, I think a very useful method might also be foreach ($users as $user) {
foreach ($user['friends'] as $friend) {
$friend = $friend->materialize(); // or maybe $friend->decode()?
$friend['name'], $friend['avatar'];
}
} |
First of all, thanks for get back to this. It would help a lot. The example you show in previous commit with syntax sugar looks promising. However, the ideal would be being able to materialize one item without materialize its soons. EG: foreach ($users as $user) {
echo $user['name']; // $user['name']->materialize() should work too
foreach ($user['friends'] as $friend) { // 'friends' instanceof Traversable, not an array/object
$friend = $friend->materialize();
$friend['name'], $friend['avatar'];
}
} So, I would differenciate between
From here, it shouldn't be difficult decode omiting one or more props |
Thanks for the feedback. I'm not sure about As for the What I'm currently wondering about is the format of the key of Additionally, if we later stack decoding on top of |
…ach in Parser now matter as new Parser is created for each level
Enable iteration inside iteration to lazily iterate any structure.
The solution lies in(It doesn't.yield from
.yield from
also tries to rewind the generator. It must be a good old iteration viaIterator
methods.) "Child" generator will be given a reference to the top levelSyntaxCheckedTokens
/Tokens
generator and willyield from
yield
from it until the end of its iteration level. Then the control will be returned back to the higher-level generator. All will be happening on the same instance ofSyntaxCheckedTokens
/Tokens
How this will reflect in public API must be well thought through.