Skip to content

Commit b1e37b9

Browse files
authored
Merge pull request #14035 from moiseev/compact-message
[stdlib] Improve the flatMap deprecation message
2 parents 01f9fc7 + aceb63e commit b1e37b9

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

stdlib/public/core/FlatMap.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ extension LazySequenceProtocol {
6060
///
6161
/// - Complexity: O(1)
6262
@inline(__always)
63-
@available(*, deprecated, renamed: "compactMap(_:)")
63+
@available(*, deprecated, renamed: "compactMap(_:)",
64+
message: "Please use compactMap(_:) for the case where closure returns an optional value")
6465
public func flatMap<ElementOfResult>(
6566
_ transform: @escaping (Elements.Element) -> ElementOfResult?
6667
) -> LazyMapSequence<
@@ -123,7 +124,8 @@ extension LazyCollectionProtocol {
123124
/// collection as its argument and returns an optional value.
124125
///
125126
/// - Complexity: O(1)
126-
@available(*, deprecated, renamed: "compactMap(_:)")
127+
@available(*, deprecated, renamed: "compactMap(_:)",
128+
message: "Please use compactMap(_:) for the case where closure returns an optional value")
127129
@_inlineable // FIXME(sil-serialize-all)
128130
public func flatMap<ElementOfResult>(
129131
_ transform: @escaping (Elements.Element) -> ElementOfResult?

stdlib/public/core/SequenceAlgorithms.swift.gyb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ extension Sequence {
783783
/// - Complexity: O(*m* + *n*), where *m* is the length of this sequence
784784
/// and *n* is the length of the result.
785785
@inline(__always)
786-
@available(*, deprecated, renamed: "compactMap(_:)")
786+
@available(*, deprecated, renamed: "compactMap(_:)",
787+
message: "Please use compactMap(_:) for the case where closure returns an optional value")
787788
public func flatMap<ElementOfResult>(
788789
_ transform: (Element) throws -> ElementOfResult?
789790
) rethrows -> [ElementOfResult] {

stdlib/public/core/StringRangeReplaceableCollection.swift.gyb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ extension Collection {
581581
return try _compactMap(transform)
582582
}
583583

584-
@available(*, deprecated, renamed: "compactMap(_:)")
584+
@available(*, deprecated, renamed: "compactMap(_:)",
585+
message: "Please use compactMap(_:) for the case where closure returns an optional value")
585586
@inline(__always)
586587
public func flatMap(
587588
_ transform: (Element) throws -> String?

test/stdlib/FlatMapDeprecation.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33
func flatMapOnSequence<
44
S : Sequence
55
>(xs: S, f: (S.Element) -> S.Element?) {
6-
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}}
6+
_ = xs.flatMap(f) // expected-warning {{'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value}} expected-note {{compactMap}}
77
}
88

99
func flatMapOnLazySequence<
1010
S : LazySequenceProtocol
1111
>(xs: S, f: (S.Element) -> S.Element?) {
12-
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}}
12+
_ = xs.flatMap(f) // expected-warning {{'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value}} expected-note {{compactMap}}
1313
}
1414

1515
func flatMapOnLazyCollection<
1616
C : LazyCollectionProtocol
1717
>(xs: C, f: (C.Element) -> C.Element?) {
18-
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}}
18+
_ = xs.flatMap(f) // expected-warning {{'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value}} expected-note {{compactMap}}
1919
}
2020

2121
func flatMapOnLazyBidirectionalCollection<
2222
C : LazyCollectionProtocol & BidirectionalCollection
2323
>(xs: C, f: (C.Element) -> C.Element?)
2424
where C.Elements : BidirectionalCollection {
25-
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}}
25+
_ = xs.flatMap(f) // expected-warning {{'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value}} expected-note {{compactMap}}
2626
}
2727

2828
func flatMapOnCollectinoOfStrings<
2929
C : Collection
3030
>(xs: C, f: (C.Element) -> String?) {
31-
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}}
31+
_ = xs.flatMap(f) // expected-warning {{'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value}} expected-note {{compactMap}}
3232
}

0 commit comments

Comments
 (0)