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

Support map/filter/reduce-like operations on documents

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.0.4
    • Component/s: None
    • Labels:
      None

      Description

      You can currently use "map" on a document since it's a sequence, this returns tuples with key/value pairs. I think we should make them feel as much like dictionaries as possible. Ideas to consider:

      1) Change DocumentIterator.next to return labeled values, a la DictionaryIterator.next. 

      2) Dictionary provides a `mapValues` method that maps over the values in a dictionary and modifies them. this would be nice to support, and we could add similar `filterValues` and `reduceValues` methods. I'm imagining an API like:

      let doc = ["a": 1, "b": 2, "c": "string", "d": nil]
      let nonNil = doc.mapValues { $0 != nil } // ["a": 1, "b": 2, "c": "string"]
      let strings = doc.filterValues { $0 is String } // ["c": "string"]

      These would at least partially alleviate current concerns about documents being append-only since removing/modifying values would be easier 

        Attachments

          Activity

            People

            Assignee:
            kaitlin.mahar Kaitlin Mahar
            Reporter:
            kaitlin.mahar Kaitlin Mahar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: