2015-10-01 21:25:17 +03:00
|
|
|
/// 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 ==.
|
2015-10-01 17:28:14 +03:00
|
|
|
public enum AnyEquatable<A>: Equatable {
|
|
|
|
case External(A, (A, A) -> Bool)
|
2015-10-01 17:29:48 +03:00
|
|
|
|
|
|
|
public var value: A {
|
|
|
|
switch self {
|
|
|
|
case let .External(a, _):
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 17:28:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public func == <A> (left: AnyEquatable<A>, right: AnyEquatable<A>) -> Bool {
|
|
|
|
switch (left, right) {
|
|
|
|
case let (.External(a, eq), .External(b, _)):
|
2015-10-01 17:34:36 +03:00
|
|
|
return eq(a, b)
|
2015-10-01 17:28:14 +03:00
|
|
|
}
|
|
|
|
}
|