Add FlatScan(First/Latest) operators #257
Open
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.
Hi community!
Here's a new Rx operator I made for a specific use case, but I've seen myself using it for more use cases so I guess it was a good candidate for this repository.
Basically,
flatScanis ascanoperator that returns anObservable<T>instead of justTand flatten the result. It's declined inflatScanFirstandflatScanLatestversions that works the same as theirflatMapcounterparts.The most useful use case is when working with paginated content when you want to make a new API request with an "offset" and append your new results to current local results. Something like that:
loadMoreTrigger .withLatestFrom(searchQuery) .flatScan(SearchResults()) { previous, query in searchResults( for: query, start: previous.elements.count, count: 20 ) .map(previous.merging) }I know I should have discussed this operator in an issue first but the code was already existing in my project but without unit tests (😱) and working on a PR directly encouraged me to write unit tests for it. If you feel like this operator doesn't fit in this repository I wouldn't mind closing this PR. At least I'll be able to add the tests to my project 😇
PS: In the second commit I fixed swift lint issues unrelated to the
flatScanoperator. Feel free to focus your review on the first commit 7332d10 😉