Skip to content
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

Use Enumerable #80

Merged
merged 1 commit into from
Apr 9, 2024
Merged

Use Enumerable #80

merged 1 commit into from
Apr 9, 2024

Conversation

cfis
Copy link
Collaborator

@cfis cfis commented Apr 9, 2024

This commit removes the custom iteration methods in the Cursor class and instead switches to Ruby's Enumerable module.

This is a backwards incompatible change because it required renaming find_all to find_by_kind (find_all is an enumerable method). In addition, the function signature changed to allow the caller to specify whether to search direct children or all children.

Also it renames visit_children to each. The each method now takes an optional parameter that specifies whether to recurse through the tree or not. By default it is true to match the previous behavior. Note you can only set this when using each, and not when using other Enumerable methods since there is now way to pass it through filter, select, etc. Also note blocks passed to the methods receive two parameters, child and parent, which might be confusing to some people (although it is like iterating through a Hash).

For my particular use case, I want to be able to control whether iteration is recursive or not.

Thoughts?

@cfis cfis force-pushed the enumerable branch 5 times, most recently from 5095651 to 83080ef Compare April 9, 2024 06:07
…change because it required renaming find_all to find_by_kind. In addition, the function signature changed to allow the caller to specify whether to search direct children or all children.
Copy link
Owner

@ioquatix ioquatix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems okay to me.

It's okay to leave specialised implementations if they can be more efficient than the generic implementations provided by Enumerable.

@ioquatix ioquatix merged commit 2ca723a into ioquatix:main Apr 9, 2024
4 checks passed
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.

2 participants