Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-372

Include bsonEquals as part of BSONValue protocol

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.1.0
    • Component/s: None
    • Labels:
      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.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: