swift-algorithms
swift-algorithms copied to clipboard
Add `recursiveMap(_:)`
add recursiveMap()
method.
Checklist
- [x] I've added at least one test that validates that my change is working, if appropriate
- [x] I've followed the code style of the rest of the project
- [x] I've read the Contribution Guidelines
- [x] I've updated the documentation if necessary
Is a "recursive mapped sequence" a term of art for a particular structure? I've never heard of it before, and the documentation so far assumes you pretty much already know. A quick web search found something related using the Python language; is the code here supposed to be a Swift adaptation of the Python code?
The concept seems to be a way to do tree traversal without that type having to provide its own depth- and breath-first iterators; you just have to supply a function to map an element to a Sequence
of its children, and this function takes care of the rest.
Is a "recursive mapped sequence" a term of art for a particular structure? I've never heard of it before, and the documentation so far assumes you pretty much already know. A quick web search found something related using the Python language; is the code here supposed to be a Swift adaptation of the Python code?
The concept seems to be a way to do tree traversal without that type having to provide its own depth- and breath-first iterators; you just have to supply a function to map an element to a
Sequence
of its children, and this function takes care of the rest.
This method is simplified recursive CTE, which can map a hierarchical table to a linear sequence.
I don’t known what’s the name of this operation. So I call it recursive map.