Open Opiumtm opened 7 years ago
I haven't documented it very well yet, but I think #36 might go at least some way to addressing this. Do you concur, or am I misreading this request?
@DavidArno it isn't recursive pattern matching. Am I wrong?
@DavidArno I may fork Succinc<T>
and then move some of my "recursive pattern matching" logic to library via pull request. You can modify it to make it more pretty later. It's ok?
That code already is successfully used in production in some of my projects. Just to mention, it's used in Html-to-Microsoft Word component in custom-made human resources management software used at my office.
@Opiumtm,
That sounds great. I can't promise which bits I'll include, but real code will help me understand how your proposal might fit in with what I'm already doing, whether yours is a better, or just a different suggestion etc. So "pull request" away 👍
I am using functional approach already in the code which analyze and transform tree-like hierarchical collections (it's transformation of source HTML DOM into Word document paragraphs or internal markup-like representation to display it later on screen).
Naturally, pattern matching is the solution for this class of problems. There are two basic functional algorithms I use:
When I have a look on
Succinc<T>
code it was interesting how my own implementation of this functional algorithms is very similar toSuccinc<T>
approach to pattern matching. So it would be good to extendSuccinc<T>
pattern matching for recursive object tree scan, matching and transformation.Basic idea is the "tree scan context" which contain original subtree nodes collection from same tree level, result collection of nodes (to insert transformed tree result) and function to get children from subtree node from context.
Example code looks like
Particularly compact representation of tree matching and transformation, I think.
Tree scan context looks like this:
Code above is provided as the idea. I don't feel it's perfect. I'm just reinvented it to solve particular and quite common problem of tree scan and transformation using functional approach and recursive pattern matching. It would be good if
Succinc<T>
do support similar feature, but more systematically and consistently implemented.