Skip to content

Commit 0fef980

Browse files
authored
SWIFT-340 Add missing documentation (#223)
1 parent aef9b5c commit 0fef980

12 files changed

+98
-16
lines changed

Sources/MongoSwift/BSON/Document+Sequence.swift

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/

Sources/MongoSwift/BSON/Document.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class DocumentStorage {
2020
self.pointer = bson_copy(pointer)
2121
}
2222

23+
/// Cleans up internal state.
2324
deinit {
2425
guard let pointer = self.pointer else {
2526
return

Sources/MongoSwift/ClientSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ClientSession: Encodable {
1010
internal init() {
1111
}
1212

13-
/// Clean up the internal mongoc_session_t.
13+
/// Cleans up internal state.
1414
deinit {
1515
}
1616

Sources/MongoSwift/MongoClient.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,7 @@ public class MongoClient {
227227
self.decoder = BSONDecoder()
228228
}
229229

230-
/**
231-
* Cleans up the internal `mongoc_client_t`.
232-
*/
230+
/// Cleans up internal state.
233231
deinit {
234232
close()
235233
}

Sources/MongoSwift/MongoCollection+BulkWrite.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ public class BulkWriteOperation {
357357
return self.isAcknowledged ? result : nil
358358
}
359359

360+
/// Cleans up internal state.
360361
deinit {
361362
guard let bulk = self.bulk else {
362363
return

Sources/MongoSwift/MongoCollection+FindAndModify.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ private class FindAndModifyOptions {
383383
}
384384
}
385385

386+
/// Cleans up internal state.
386387
deinit {
387388
guard let options = self._options else {
388389
return

Sources/MongoSwift/MongoCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class MongoCollection<T: Codable> {
6161
self.decoder = withDecoder
6262
}
6363

64-
/// Deinitializes a `MongoCollection`, cleaning up the internal `mongoc_collection_t`
64+
/// Cleans up internal state.
6565
deinit {
6666
guard let collection = self._collection else {
6767
return

Sources/MongoSwift/MongoCursor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class MongoCursor<T: Codable>: Sequence, IteratorProtocol {
3838
}
3939
}
4040

41-
/// Deinitializes a `MongoCursor`, cleaning up the internal `mongoc_cursor_t`.
41+
/// Cleans up internal state.
4242
deinit {
4343
self.close()
4444
}

Sources/MongoSwift/MongoDatabase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public class MongoDatabase {
241241
self.decoder = decoder
242242
}
243243

244-
/// Deinitializes a MongoDatabase, cleaning up the internal `mongoc_database_t`.
244+
/// Cleans up internal state.
245245
deinit {
246246
guard let database = self._database else {
247247
return

Sources/MongoSwift/ReadConcern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class ReadConcern: Codable {
8686
try container.encodeIfPresent(self.level, forKey: .level)
8787
}
8888

89-
/// Cleans up the internal `mongoc_read_concern_t`.
89+
/// Cleans up internal state.
9090
deinit {
9191
guard let readConcern = self._readConcern else {
9292
return

0 commit comments

Comments
 (0)