-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Infallible's flatMap family of operators that can return an Infallible that is not, in fact, infallible #2536
Open
nikolaykasyanov
wants to merge
3
commits into
ReactiveX:main
Choose a base branch
from
nikolaykasyanov:fix-infallible-flatMap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−7
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,21 +263,34 @@ extension InfallibleType { | |
// MARK: - FlatMap | ||
extension InfallibleType { | ||
/** | ||
Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence. | ||
Projects each element of an infallible sequence to an observable sequence and merges the resulting observable sequences into one observable sequence. | ||
|
||
- seealso: [flatMap operator on reactivex.io](http://reactivex.io/documentation/operators/flatmap.html) | ||
|
||
- parameter selector: A transform function to apply to each element. | ||
- returns: An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. | ||
*/ | ||
public func flatMap<Source: ObservableConvertibleType>(_ selector: @escaping (Element) -> Source) | ||
-> Infallible<Source.Element> { | ||
-> Observable<Source.Element> { | ||
asObservable().flatMap(selector) | ||
} | ||
|
||
/** | ||
Projects each element of an infallible sequence to an infallible sequence and merges the resulting infallible sequences into one infallible sequence. | ||
|
||
- seealso: [flatMap operator on reactivex.io](http://reactivex.io/documentation/operators/flatmap.html) | ||
|
||
- parameter selector: A transform function to apply to each element. | ||
- returns: An infallible sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. | ||
*/ | ||
public func flatMap<Result>(_ selector: @escaping (Element) -> Infallible<Result>) | ||
-> Infallible<Result> { | ||
Infallible(asObservable().flatMap(selector)) | ||
} | ||
|
||
/** | ||
Projects each element of an observable sequence into a new sequence of observable sequences and then | ||
transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence. | ||
Projects each element of an infallible sequence into a new sequence of observable sequences and then | ||
transforms the observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence. | ||
|
||
It is a combination of `map` + `switchLatest` operator | ||
|
||
|
@@ -288,12 +301,29 @@ extension InfallibleType { | |
Observable of Observable sequences and that at any point in time produces the elements of the most recent inner observable sequence that has been received. | ||
*/ | ||
public func flatMapLatest<Source: ObservableConvertibleType>(_ selector: @escaping (Element) -> Source) | ||
-> Infallible<Source.Element> { | ||
-> Observable<Source.Element> { | ||
asObservable().flatMapLatest(selector) | ||
} | ||
|
||
/** | ||
Projects each element of an infallible sequence into a new sequence of infallible sequences and then | ||
transforms the infallible sequence of infallible sequences into an infallible sequence producing values only from the most recent infallible sequence. | ||
|
||
It is a combination of `map` + `switchLatest` operator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be removed to avoid misunderstandings |
||
|
||
- seealso: [flatMapLatest operator on reactivex.io](http://reactivex.io/documentation/operators/flatmap.html) | ||
|
||
- parameter selector: A transform function to apply to each element. | ||
- returns: An infallible sequence whose elements are the result of invoking the transform function on each element of source producing an | ||
Infallible of Infallible sequences and that at any point in time produces the elements of the most recent inner infallible sequence that has been received. | ||
*/ | ||
public func flatMapLatest<Result>(_ selector: @escaping (Element) -> Infallible<Result>) | ||
-> Infallible<Result> { | ||
Infallible(asObservable().flatMapLatest(selector)) | ||
} | ||
|
||
/** | ||
Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence. | ||
Projects each element of an infallible sequence to an observable sequence and merges the resulting observable sequences into one observable sequence. | ||
If element is received while there is some projected observable sequence being merged it will simply be ignored. | ||
|
||
- seealso: [flatMapFirst operator on reactivex.io](http://reactivex.io/documentation/operators/flatmap.html) | ||
|
@@ -302,7 +332,21 @@ extension InfallibleType { | |
- returns: An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence that was received while no other sequence was being calculated. | ||
*/ | ||
public func flatMapFirst<Source: ObservableConvertibleType>(_ selector: @escaping (Element) -> Source) | ||
-> Infallible<Source.Element> { | ||
-> Observable<Source.Element> { | ||
asObservable().flatMapFirst(selector) | ||
} | ||
|
||
/** | ||
Projects each element of an infallible sequence to an infallible sequence and merges the resulting infallible sequences into one infallible sequence. | ||
If element is received while there is some projected infallible sequence being merged it will simply be ignored. | ||
|
||
- seealso: [flatMapFirst operator on reactivex.io](http://reactivex.io/documentation/operators/flatmap.html) | ||
|
||
- parameter selector: A transform function to apply to element that was observed while no observable is executing in parallel. | ||
- returns: An infallible sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence that was received while no other sequence was being calculated. | ||
*/ | ||
public func flatMapFirst<Result>(_ selector: @escaping (Element) -> Infallible<Result>) | ||
-> Infallible<Result> { | ||
Infallible(asObservable().flatMapFirst(selector)) | ||
} | ||
} | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. It should be merged and released 🙏