1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Switch in Free.map directly.

This commit is contained in:
Rob Rix 2015-11-03 11:19:33 -05:00
parent 02af784036
commit 4f16ce62c3

View File

@ -91,7 +91,12 @@ public enum Free<Leaf, Annotation, Value>: CustomDebugStringConvertible {
// MARK: Functor
public func map<C>(@noescape transform: Value throws -> C) rethrows -> Free<Leaf, Annotation, C> {
return try analysis(ifPure: { try .Pure(transform($0)) }, ifRoll: { try .Roll($0, $1.map { try $0.map(transform) }) })
switch self {
case let .Pure(a):
return try .Pure(transform(a))
case let .Roll(annotation, syntax):
return try .Roll(annotation, syntax.map { try $0.map(transform) })
}
}