Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
None
-
None
Description
bsonEquals is long and full of duplicated code. It's also prone to bugs if we forget to update it when we conform a new type to BSONValue. We should amend the BSONValue protocol to include the bsonEquals functionality, and add extension like this:
extension BSONValue where Self: Equatable {
|
func bsonEquals(other: BSONValue) {
|
guard let otherAsEquatable = other as? Self else { return false } |
return self == otherAsEquatable |
}
|
}
|
For all BSONValues that conform to Equatable, the bsonEquals defined here will work automagically. This should include every BSONValue except for Array, which will require some additional massaging. It will give us a compiler error if we introduce a BSONValue type that doesn't conform to Equatable or implement this function, which is nice.
With this design, we'll be able to do a.bsonEquals(b) and remove the standalone bsonEquals function we have now, or replace the large body with simply lhs.bsonEquals(rhs).
This all requires conditional conformance, so it will have to come after we officially drop Swift 4.1.