dream-html icon indicating copy to clipboard operation
dream-html copied to clipboard

fold / iterator

Open samoht opened this issue 1 year ago • 3 comments

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.

samoht avatar Nov 06 '24 22:11 samoht

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

yawaramin avatar Nov 06 '24 22:11 yawaramin

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.

samoht avatar Nov 07 '24 17:11 samoht

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

yawaramin avatar Nov 12 '24 04:11 yawaramin

It turned out to be a bit more complex than my initial guess. Can you check the PR?

yawaramin avatar Jun 27 '25 02:06 yawaramin