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

fold / iterator #32

Open
samoht opened this issue Nov 6, 2024 · 3 comments
Open

fold / iterator #32

samoht opened this issue Nov 6, 2024 · 3 comments

Comments

@samoht
Copy link

samoht commented Nov 6, 2024

Would you be interested in a contribution that would add an iterator or folder over the nodes? For instance, the use-case would be to get all the classes defined in a document.

@yawaramin
Copy link
Owner

Can you show one or two examples of the usages you are thinking of?

@samoht
Copy link
Author

samoht commented Nov 7, 2024

Something like val fold_attrs: ('a -> (string * string) -> 'a) -> 'a -> node -> 'a ? Ie. fold a function over all the attributes of a node and its children. I've picked fold_left here, but I'm fine with whatever argument order. As attr and node are abstracts (as they should be!), it's impossible to write such a function outside the lib.

@yawaramin
Copy link
Owner

To be honest I'm not totally sure but would you mind sending the PR and a couple of tests? If the implementation is reasonable I'll just merge it. Let's do this signature:

val fold_attrs : ('a -> name:string -> value:string -> 'a) -> 'a -> node -> 'a

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

No branches or pull requests

2 participants