mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Inline reduction in Free.sum
.
This commit is contained in:
parent
2963a76943
commit
f2004a22b8
@ -75,7 +75,18 @@ public enum Free<Leaf, Annotation, Value>: CustomDebugStringConvertible {
|
||||
|
||||
/// Returns a function which sums `Free`s by first `transform`ing `Pure` values into integers, and then summing these.
|
||||
public static func sum(@noescape transform: Value -> Int)(_ free: Free) -> Int {
|
||||
return free.map(transform).reduce(0, combine: +)
|
||||
return free.map(transform).cata {
|
||||
switch $1 {
|
||||
case .Leaf:
|
||||
return 0
|
||||
case let .Indexed(a):
|
||||
return a.reduce(0, combine: +)
|
||||
case let .Fixed(a):
|
||||
return a.reduce(0, combine: +)
|
||||
case let .Keyed(a):
|
||||
return a.values.reduce(0, combine: +)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user