Skip to content

Instantly share code, notes, and snippets.

@dictav
Last active November 22, 2015 10:25
Show Gist options
  • Save dictav/f8740ff4958fbed7b5d6 to your computer and use it in GitHub Desktop.
Save dictav/f8740ff4958fbed7b5d6 to your computer and use it in GitHub Desktop.
typealias TwoEquatables = (Equatable, Equatable)
func == (lhs: TwoEquatables, rhs: TwoEquatables) -> Bool {
let t1 = _reflect(lhs.0)
let t2 = _reflect(rhs.0)
let u1 = _reflect(lhs.1)
let u2 = _reflect(rhs.1)
return t1.valueType == t2.valueType && t1.summary == t2.summary
&& u1.valueType == u2.valueType && u1.summary == u2.summary
}
extension SequenceType where Self.Generator.Element == TwoEquatables {
func contains(element: TwoEquatables) -> Bool {
return contains { $0 == element }
}
}
let a: [TwoEquatables] = [(1,"1"), (2,2)]
print(a.contains((1,1)))
typealias TwoEquatables = (Equatable, Equatable)
let a: [TwoEquatables] = [(1,1), (2,2), (3, "3")]
let b: [TwoEquatables] = [("1",1), (2,2), (3, 3)]
extension SequenceType where Self.Generator.Element == TwoEquatables {
func contains<T1: Equatable, T2: Equatable>(el: (T1, T2)) -> Bool {
return (self).contains {
guard let e0 = $0.0 as? T1, e1 = $0.1 as? T2 else {
return false
}
return e0 == el.0 && e1 == el.1
}
}
}
a.contains((1,1))
b.contains((1,1))
a.contains(("1",1))
b.contains(("1",1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment