mirror of
https://github.com/github/semantic.git
synced 2024-11-25 11:04:00 +03:00
Rename the Syntax piecewise equality functions after the type parameters (mostly).
This commit is contained in:
parent
831f8dcbae
commit
40fe88b4a4
@ -76,7 +76,7 @@ extension Cofree {
|
||||
extension Cofree {
|
||||
public static func equals(annotation annotation: (Annotation, Annotation) -> Bool, leaf: (Leaf, Leaf) -> Bool)(_ left: Cofree, _ right: Cofree) -> Bool {
|
||||
return annotation(left.extract, right.extract)
|
||||
&& Syntax.equals(ifLeaf: leaf, ifRecur: Cofree.equals(annotation: annotation, leaf: leaf))(left.unwrap, right.unwrap)
|
||||
&& Syntax.equals(leaf: leaf, recur: Cofree.equals(annotation: annotation, leaf: leaf))(left.unwrap, right.unwrap)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ extension Free {
|
||||
case let (.Pure(a), .Pure(b)):
|
||||
return pure(a, b)
|
||||
case let (.Roll(a), .Roll(b)):
|
||||
return Syntax.equals(ifLeaf: leaf, ifRecur: equals(pure: pure, leaf: leaf))(a, b)
|
||||
return Syntax.equals(leaf: leaf, recur: equals(pure: pure, leaf: leaf))(a, b)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
@ -52,14 +52,14 @@ extension Syntax: DictionaryLiteralConvertible {
|
||||
// MARK: - Equality
|
||||
|
||||
extension Syntax {
|
||||
public static func equals(ifLeaf ifLeaf: (A, A) -> Bool, ifRecur: (Recur, Recur) -> Bool)(_ left: Syntax<Recur, A>, _ right: Syntax<Recur, A>) -> Bool {
|
||||
public static func equals(leaf leaf: (A, A) -> Bool, recur: (Recur, Recur) -> Bool)(_ left: Syntax<Recur, A>, _ right: Syntax<Recur, A>) -> Bool {
|
||||
switch (left, right) {
|
||||
case let (.Leaf(l1), .Leaf(l2)):
|
||||
return ifLeaf(l1, l2)
|
||||
return leaf(l1, l2)
|
||||
case let (.Indexed(v1), .Indexed(v2)):
|
||||
return v1.count == v2.count && zip(v1, v2).lazy.map(ifRecur).reduce(true) { $0 && $1 }
|
||||
return v1.count == v2.count && zip(v1, v2).lazy.map(recur).reduce(true) { $0 && $1 }
|
||||
case let (.Keyed(d1), .Keyed(d2)):
|
||||
return Set(d1.keys) == Set(d2.keys) && d1.keys.map { ifRecur(d1[$0]!, d2[$0]!) }.reduce(true) { $0 && $1 }
|
||||
return Set(d1.keys) == Set(d2.keys) && d1.keys.map { recur(d1[$0]!, d2[$0]!) }.reduce(true) { $0 && $1 }
|
||||
default:
|
||||
return false
|
||||
}
|
||||
@ -67,7 +67,7 @@ extension Syntax {
|
||||
}
|
||||
|
||||
public func == <F: Equatable, A: Equatable> (left: Syntax<F, A>, right: Syntax<F, A>) -> Bool {
|
||||
return Syntax.equals(ifLeaf: ==, ifRecur: ==)(left, right)
|
||||
return Syntax.equals(leaf: ==, recur: ==)(left, right)
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ extension TermType {
|
||||
|
||||
extension TermType {
|
||||
public static func equals(leaf: (Leaf, Leaf) -> Bool)(_ a: Self, _ b: Self) -> Bool {
|
||||
return Syntax.equals(ifLeaf: leaf, ifRecur: equals(leaf))(a.unwrap, b.unwrap)
|
||||
return Syntax.equals(leaf: leaf, recur: equals(leaf))(a.unwrap, b.unwrap)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user