-
Notifications
You must be signed in to change notification settings - Fork 32
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
Added Result merge method #225
Conversation
Hi, thanks for the PR. Do you have any reference for the merge operator? Who else is using it? I would prefer operators like |
Happy to contribute 🙂
There is an
Simple example: def create(customer_id: str, email: str) -> HTTPResponse:
service_result: Result[Customer, InvalidEmailAddress] = service.create_customer(customer_id, email)
response: HTTPResponse = service_result.map(customer_to_response).map_error(invalid_email_to_response).merge()
return response I think the above code might also benefit from a Example (removing the extra variables from the above which I have included to highlight the types): def create(customer_id: str, email: str) -> HTTPResponse:
return (
service.create_customer(customer_id, email)
.bimap(customer_to_response, invalid_email_to_response)
.merge()
) |
I've created a PR to add the |
Sorry I think I made a merge conflict with your PR. Anyways, I see that |
Also: * `is_ok` and `is_error` use a comparison instead of a match as the comparison is faster * Fixed a typo
94be4b6
to
65fd24d
Compare
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.
Nice, thanks for contributing this
Nice catch on the |
Also:
is_ok
andis_error
use a comparison instead of a match as the comparison is faster