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

Convenience constructor taking a Patch cost function.

This commit is contained in:
Rob Rix 2015-10-15 15:28:21 -04:00
parent 53c78fd546
commit 24c66eb1ff

View File

@ -16,6 +16,11 @@ public struct Interpreter<Term: TermType> {
self.cost = cost self.cost = cost
} }
/// Constructs an `Interpreter` parameterized by the `equal` and `comparable` tests on `Term`s, and the `cost` function for `Patch`es.
public init(equal: (Term, Term) -> Bool, comparable: (Term, Term) -> Bool, cost: Patch<Term> -> Int) {
self.init(equal: equal, comparable: comparable, cost: { $0.map(cost).reduce(0, combine: +) })
}
/// Run the interpreter over a given pair of `Term`s, producing a `Diff` as its result. /// Run the interpreter over a given pair of `Term`s, producing a `Diff` as its result.
public func run(a: Term, _ b: Term) -> Diff { public func run(a: Term, _ b: Term) -> Diff {