@@ -574,41 +574,6 @@ extension Sequence {
574
574
}
575
575
576
576
extension Collection {
577
- /// Returns an array containing the non-`nil` strings resulting from the given
578
- /// transformation on each element of this sequence.
579
- ///
580
- /// Use this method to receive an array of non-optional strings when your
581
- /// transformation produces a `String?`.
582
- ///
583
- /// In this example, note the difference in the result of using `map` and
584
- /// `compactMap` with a transformation that returns a `String?` value.
585
- ///
586
- /// let errorLookup = [400: "Bad request",
587
- /// 403: "Forbidden",
588
- /// 404: "Not found"]
589
- ///
590
- /// let errorCodes = [400, 407, 404]
591
- ///
592
- /// let mapped: [String?] = errorCodes.map { code in errorLookup[code] }
593
- /// // ["Bad request", nil, "Not found"]
594
- ///
595
- /// let compactMapped: [String] = errorCodes.compactMap { code in errorLookup[code] }
596
- /// // ["Bad request", "Not found"]
597
- ///
598
- /// - Parameter transform: A closure that accepts an element of this
599
- /// sequence as its argument and returns a `String?`.
600
- /// - Returns: An array of the non-`nil` results of calling `transform`
601
- /// with each element of the sequence.
602
- ///
603
- /// - Complexity: O(*m* + *n*), where *m* is the length of this sequence
604
- /// and *n* is the length of the result.
605
- @_inlineable // FIXME(sil-serialize-all)
606
- public func compactMap(
607
- _ transform: (Element) throws -> String?
608
- ) rethrows -> [String] {
609
- return try _compactMap(transform)
610
- }
611
-
612
577
@available(swift, deprecated: 4.1, renamed: "compactMap(_:)",
613
578
message: "Please use compactMap(_:) for the case where closure returns an optional value")
614
579
@inline(__always)
0 commit comments