forked from ReactiveX/RxSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAny+Equatable.swift
43 lines (35 loc) · 909 Bytes
/
Any+Equatable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Any+Equatable.swift
// Rx
//
// Created by Krunoslav Zaher on 12/19/15.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
import Foundation
/**
A way to use built in XCTest methods with objects that are partially equatable.
If this can be done simpler, PRs are welcome :)
*/
struct AnyEquatable<Target>
: Equatable
, CustomDebugStringConvertible
, CustomStringConvertible {
typealias Comparer = (Target, Target) -> Bool
let _target: Target
let _comparer: Comparer
init(target: Target, comparer: Comparer) {
_target = target
_comparer = comparer
}
}
func == <T>(lhs: AnyEquatable<T>, rhs: AnyEquatable<T>) -> Bool {
return lhs._comparer(lhs._target, rhs._target)
}
extension AnyEquatable {
var description: String {
return "\(_target)"
}
var debugDescription: String {
return "\(_target)"
}
}