Skip to content

Instantly share code, notes, and snippets.

@elliottwilliams
Last active May 6, 2018 13:57
Show Gist options
  • Select an option

  • Save elliottwilliams/42d4b322036317e69efd91ddfb0629fc to your computer and use it in GitHub Desktop.

Select an option

Save elliottwilliams/42d4b322036317e69efd91ddfb0629fc to your computer and use it in GitHub Desktop.
Type-erased Equatable container in Swift 4
struct AnyEquatable: Equatable {
let equalTo: (Any) -> Bool
let value: Any
init<V: Equatable>(_ value: V) {
self.value = value
equalTo = { ($0 as? V) == value }
}
static func == (lhs: AnyEquatable, rhs: AnyEquatable) -> Bool {
return lhs.equalTo(rhs.value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment