1
1
mirror of https://github.com/github/semantic.git synced 2024-12-12 14:45:40 +03:00
semantic/prototype/Doubt/AnyEquatable.swift
2015-10-01 14:25:17 -04:00

21 lines
565 B
Swift

/// An Equatable instance for any type for which you can provide an equality function.
///
/// This can enable equating [T] where T does not conform to Equatable, by first mapping to [AnyEquatable<T>] and then comparing with ==.
public enum AnyEquatable<A>: Equatable {
case External(A, (A, A) -> Bool)
public var value: A {
switch self {
case let .External(a, _):
return a
}
}
}
public func == <A> (left: AnyEquatable<A>, right: AnyEquatable<A>) -> Bool {
switch (left, right) {
case let (.External(a, eq), .External(b, _)):
return eq(a, b)
}
}