swift-algorithms icon indicating copy to clipboard operation
swift-algorithms copied to clipboard

Add `recursiveMap(_:)`

Open SusanDoggie opened this issue 2 years ago • 2 comments

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

SusanDoggie avatar Mar 27 '22 16:03 SusanDoggie

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.

CTMacUser avatar Apr 02 '22 21:04 CTMacUser

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.

SusanDoggie avatar Apr 03 '22 03:04 SusanDoggie