-
Notifications
You must be signed in to change notification settings - Fork 163
Add mapToResult operator, tests #79
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #79 +/- ##
==========================================
+ Coverage 97.01% 97.10% +0.09%
==========================================
Files 60 62 +2
Lines 3215 3315 +100
==========================================
+ Hits 3119 3219 +100
Misses 96 96
Continue to review full report at Codecov.
|
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.
I think this looks great, thanks for taking up the idea!
Would love to see this land, thanks @kaphacius! I use TCA’s
+1. (and as a heads up, we’ll probs need some quick docs. in the README.md, for when you get a chance. 🙏🏽) |
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.
Thanks! Tests look good overall, but there are some formatting issues, for example usage of unneeded parentheses, using keywords like catch
and throw
as functions (e.g. catch (let e)
, throw(MyError.error)
.
If you'll clean up these things I'll be happy to merge.
Thank you!
Added info to README.md and applied all of the suggested comments 👍 |
Is there any particular reason not to make the name of this something more general, like (I have this operator in my code base as |
I agree about @jshier's remarks and this is the biggest gripe I have here. Something like maoToResult or something else makes more sense, but there's "prior art" with TCA's catchToEffect. Not sure that's really a strong enough reason to not give it our own naming. |
I don't have any attachment to the name to be honest, I think |
Renamed the operator, tests and the PR name :) |
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.
Looks great! Thank you :)
This PR adds a new operator
catchToResult
which allows transforming aPublisher
that has a specificFailure
type (notNever
) into a publisher that outputsOutput
andFailure
wrapped in aResult
.A common use-case for this is when an interface should produce publishers of type
AnyPublisher<Result<T, Error>, Never>
, but the underlying code works with publishers likeAnyPublisher<T, Error>
(URLSession.DataTaskPublisher
).The opposite situation, going from
AnyPublisher<Result<T, Error>, Never>
toAnyPublisher<T, Error>
also happens. If there is an interest in this PR I can open another one with an operator that allows doing that.