@@ -30,13 +30,11 @@ extension Document: Sequence {
3030 }
3131
3232 /**
33- * Returns a new document containing the keys of this document with the values transformed by
34- * the given closure.
33+ * Returns a new document containing the keys of this document with the values transformed by the given closure.
3534 *
3635 * - Parameters:
37- * - transform: A closure that transforms a `BSONValue`. `transform` accepts each value of the
38- * document as its parameter and returns a transformed `BSONValue` of the same or
39- * of a different type.
36+ * - transform: A closure that transforms a `BSONValue`. `transform` accepts each value of the document as its
37+ * parameter and returns a transformed `BSONValue` of the same or of a different type.
4038 *
4139 * - Returns: A document containing the keys and transformed values of this document.
4240 *
@@ -50,6 +48,14 @@ extension Document: Sequence {
5048 return output
5149 }
5250
51+ /**
52+ * Returns a document containing all but the given number of initial key-value pairs.
53+ *
54+ * - Parameters:
55+ * - k: The number of key-value pairs to drop from the beginning of the document. k must be > 0.
56+ *
57+ * - Returns: A document starting after the specified number of key-value pairs.
58+ */
5359 public func dropFirst( _ n: Int ) -> Document {
5460 switch n {
5561 case ..< 0 :
@@ -64,6 +70,14 @@ extension Document: Sequence {
6470 }
6571 }
6672
73+ /**
74+ * Returns a document containing all but the given number of final key-value pairs.
75+ *
76+ * - Parameters:
77+ * - k: The number of key-value pairs to drop from the end of the document. Must be greater than or equal to zero.
78+ *
79+ * - Returns: A document leaving off the specified number of final key-value pairs.
80+ */
6781 public func dropLast( _ n: Int ) -> Document {
6882 switch n {
6983 case ..< 0 :
@@ -78,6 +92,17 @@ extension Document: Sequence {
7892 }
7993 }
8094
95+ /**
96+ * Returns a document by skipping the initial, consecutive key-value pairs that satisfy the given predicate.
97+ *
98+ * - Parameters:
99+ * - predicate: A closure that takes a key-value pair as its argument and returns a boolean indicating whether
100+ * the key-value pair should be included in the result.
101+ *
102+ * - Returns: A document starting after the initial, consecutive key-value pairs that satisfy `predicate`.
103+ *
104+ * - Throws: An error if `predicate` throws an error.
105+ */
81106 public func drop( while predicate: ( KeyValuePair ) throws -> Bool ) rethrows -> Document {
82107 // tracks whether we are still in a "dropping" state. once we encounter
83108 // an element that doesn't satisfy the predicate, we stop dropping.
@@ -97,6 +122,14 @@ extension Document: Sequence {
97122 }
98123 }
99124
125+ /**
126+ * Returns a document, up to the specified maximum length, containing the initial key-value pairs of the document.
127+ *
128+ * - Parameters:
129+ * - maxLength: The maximum length for the returned document. Must be greater than or equal to zero.
130+ *
131+ * - Returns: A document starting at the beginning of this document with at most `maxLength` key-value pairs.
132+ */
100133 public func prefix( _ maxLength: Int ) -> Document {
101134 switch maxLength {
102135 case ..< 0 :
@@ -109,6 +142,17 @@ extension Document: Sequence {
109142 }
110143 }
111144
145+ /**
146+ * Returns a document containing the initial, consecutive key-value pairs that satisfy the given predicate.
147+ *
148+ * - Parameters:
149+ * - predicate: A closure that takes a key-value pair as its argument and returns a boolean indicating whether
150+ * the key-value pair should be included in the result.
151+ *
152+ * - Returns: A document containing the initial, consecutive key-value pairs that satisfy `predicate`.
153+ *
154+ * - Throws: An error if `predicate` throws an error.
155+ */
112156 public func prefix( while predicate: ( KeyValuePair ) throws -> Bool ) rethrows -> Document {
113157 var output = Document ( )
114158 for elt in self {
@@ -118,6 +162,14 @@ extension Document: Sequence {
118162 return output
119163 }
120164
165+ /**
166+ * Returns a document, up to the specified maximum length, containing the final key-value pairs of the document.
167+ *
168+ * - Parameters:
169+ * - maxLength: The maximum length for the returned document. Must be greater than or equal to zero.
170+ *
171+ * - Returns: A document ending at the end of this document with at most `maxLength` key-value pairs.
172+ */
121173 public func suffix( _ maxLength: Int ) -> Document {
122174 switch maxLength {
123175 case ..< 0 :
@@ -131,6 +183,26 @@ extension Document: Sequence {
131183 }
132184 }
133185
186+ /**
187+ * Returns the longest possible subsequences of the document, in order, that don’t contain key-value pairs
188+ * satisfying the given predicate. Key-value pairs that are used to split the document are not returned as part of
189+ * any subsequence.
190+ *
191+ * - Parameters:
192+ * - maxSplits: The maximum number of times to split the document, or one less than the number of subsequences to
193+ * return. If `maxSplits` + 1 subsequences are returned, the last one is a suffix of the original
194+ * document containing the remaining key-value pairs. `maxSplits` must be greater than or equal to
195+ * zero. The default value is `Int.max`.
196+ * - omittingEmptySubsequences: If false, an empty document is returned in the result for each pair of
197+ * consecutive key-value pairs satisfying the `isSeparator` predicate and for each
198+ * key-value pair at the start or end of the document satisfying the `isSeparator`
199+ * predicate. If true, only nonempty documents are returned. The default value is
200+ * true.
201+ * - isSeparator: A closure that returns true if its argument should be used to split the document and otherwise
202+ * returns false.
203+ *
204+ * - Returns: An array of documents, split from this document's key-value pairs.
205+ */
134206 public func split( maxSplits: Int = Int . max,
135207 omittingEmptySubsequences: Bool = true ,
136208 whereSeparator isSeparator: ( KeyValuePair ) throws -> Bool ) rethrows -> [ Document ] {
@@ -158,13 +230,13 @@ extension Document {
158230 // this variant is called by default, but the other is still accessible by explicitly stating
159231 // return type: `let newDocPairs: [Document.KeyValuePair] = newDoc.filter { ... }`
160232 /**
161- * Returns a new document containing the key-value pairs of the dictionary that satisfy the given predicate.
233+ * Returns a new document containing the elements of the document that satisfy the given predicate.
162234 *
163235 * - Parameters:
164236 * - isIncluded: A closure that takes a key-value pair as its argument and returns a `Bool` indicating whether
165237 * the pair should be included in the returned document.
166238 *
167- * - Returns: A document of the key-value pairs that `isIncluded` allows.
239+ * - Returns: A document containing the key-value pairs that `isIncluded` allows.
168240 *
169241 * - Throws: An error if `isIncluded` throws an error.
170242 */
0 commit comments