apple / swift-algorithms

Commonly used sequence and collection algorithms for Swift
Apache License 2.0
5.9k stars 435 forks source link

Add `recursiveMap(_:)` #185

Open SusanDoggie opened 2 years ago

SusanDoggie commented 2 years ago

add recursiveMap() method.

Checklist

CTMacUser commented 2 years ago

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.

SusanDoggie commented 2 years ago

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.