-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stdlib] Introduce compactMap and deprecate one flatMap variant (#13807)
This is the implementation of [SE-0187](https://github.com/apple/swift-evolution/blob/master/proposals/0187-introduce-filtermap.md) <rdar://problem/34918180> Cherrypicked and squashed from the following commits: 6f7aecd fb49b3e 8ec6c45 96d3439 128092a
- Loading branch information
1 parent
afc8bad
commit c167720
Showing
10 changed files
with
134 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// RUN: %target-typecheck-verify-swift %s | ||
|
||
func flatMapOnSequence< | ||
S : Sequence | ||
>(xs: S, f: (S.Element) -> S.Element?) { | ||
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}} | ||
} | ||
|
||
func flatMapOnLazySequence< | ||
S : LazySequenceProtocol | ||
>(xs: S, f: (S.Element) -> S.Element?) { | ||
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}} | ||
} | ||
|
||
func flatMapOnLazyCollection< | ||
C : LazyCollectionProtocol | ||
>(xs: C, f: (C.Element) -> C.Element?) { | ||
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}} | ||
} | ||
|
||
func flatMapOnLazyBidirectionalCollection< | ||
C : LazyCollectionProtocol & BidirectionalCollection | ||
>(xs: C, f: (C.Element) -> C.Element?) | ||
where C.Elements : BidirectionalCollection { | ||
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}} | ||
} | ||
|
||
func flatMapOnCollectinoOfStrings< | ||
C : Collection | ||
>(xs: C, f: (C.Element) -> String?) { | ||
_ = xs.flatMap(f) // expected-warning {{deprecated}} expected-note {{compactMap}} | ||
} |