1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 21:52:59 +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)
}
}