1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

TermType has a size property.

This commit is contained in:
Rob Rix 2015-10-14 18:47:20 -04:00
parent b0cb77ae74
commit b4a9564747

View File

@ -10,6 +10,21 @@ extension TermType {
public func cata<Result>(transform: Syntax<Result, LeafType> -> Result) -> Result {
return self |> ({ $0.out } >>> { $0.map { $0.cata(transform) } } >>> transform)
}
/// The size of the receiver.
public var size: Int {
return cata {
switch $0 {
case .Leaf:
return 1
case let .Indexed(i):
return i.reduce(1, combine: +)
case let .Keyed(k):
return k.values.reduce(1, combine: +)
}
}
}
}