mirror of
https://github.com/github/semantic.git
synced 2024-11-25 11:04:00 +03:00
Tacit unwrapping.
This commit is contained in:
parent
89adf2cc86
commit
4cc87bc0cf
@ -15,14 +15,14 @@ extension TermType {
|
||||
///
|
||||
/// 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.
|
||||
public func cata<Result>(transform: Syntax<Result, LeafType> -> Result) -> Result {
|
||||
return self |> ({ $0.unwrap } >>> { $0.map { $0.cata(transform) } } >>> transform)
|
||||
return self |> (Self.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)
|
||||
return self |> (Self.unwrap >>> { $0.map { ($0, $0.para(transform)) } } >>> transform)
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user