1
1
mirror of https://github.com/github/semantic.git synced 2024-12-11 08:45:48 +03:00
semantic/prototype/Doubt/Operation.swift

33 lines
958 B
Swift
Raw Normal View History

2015-10-14 18:40:43 +03:00
/// An operation of diffing over terms or collections of terms.
public enum Operation<Recur, Term, Diff> {
/// Indicates that diffing should compare the enclosed `Term`s.
///
/// When run, the enclosed function will be applied to the resulting `Diff`.
case Recursive(Term, Term, Diff -> Recur)
/// Represents a diff to be performed on a collection of terms identified by keys.
case ByKey([String:Term], [String:Term], [String:Diff] -> Recur)
/// Represents a diff to be performed over an array of terms by index.
case ByIndex([Term], [Term], [Diff] -> Recur)
}
2015-10-14 18:40:43 +03:00
// MARK: - Functor
2015-10-14 18:40:43 +03:00
extension Operation {
2015-10-14 18:40:43 +03:00
public func map<Other>(transform: Recur -> Other) -> Operation<Other, Term, Diff> {
switch self {
case let .Recursive(a, b, f):
return .Recursive(a, b, f >>> transform)
case let .ByKey(a, b, f):
return .ByKey(a, b, f >>> transform)
case let .ByIndex(a, b, f):
return .ByIndex(a, b, f >>> transform)
}
}
}
import Prelude