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

Include bsonEquals as part of BSONValue protocol

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 0.1.0
    • 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.

      Attachments

        Activity

          People

            patrick.freed@mongodb.com Patrick Freed
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: