1
1
mirror of https://github.com/github/semantic.git synced 2024-11-25 11:04:00 +03:00

Document paramorphism.

This commit is contained in:
Rob Rix 2015-10-19 11:17:18 -04:00
parent d9823f144e
commit 7b94606558

View File

@ -14,6 +14,9 @@ extension TermType {
return self |> ({ $0.unwrap } >>> { $0.map { $0.cata(transform) } } >>> transform)
}
/// Paramorphism over `TermType`s.
///
/// Folds the tree encoded by the receiver into a single value by recurring top-down through the tree, applying `transform` to leaves, then to branches, and so forth. Each recursive instance is made available in the `Syntax` alongside the result value at that node.
public func para<Result>(transform: (Syntax<(Self, Result), LeafType>) -> Result) -> Result {
return self |> ({ $0.unwrap } >>> { $0.map { ($0, $0.para(transform)) } } >>> transform)
}