Skip to content
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

Add extensions for ResponseMessage like Kotlin's Result type #40

Merged

Conversation

kohenkatz
Copy link
Contributor

@kohenkatz kohenkatz commented Apr 28, 2023

The ResponseMessage type is very similar to Kotlin's built-in Result type. The only major difference is that the ResponseMessage type has additional fields for response code, headers, and trailers.

The Kotlin Result type has a number of convenient extension functions which can simplify many common coding situations. For example, getOrThrow is useful for situations where a code block is already surrounded by a try/catch, and getOrNull/getOrDefault are useful for situations in which a failure is not critical. Other places in this library already contain fold methods similar to the Result type.

This PR adds extension functions to ResponseMessage that match the ones present on Result.

I'm not sure what type of tests are appropriate for these functions, if any, considering that I don't see any tests for the Kotlin Result implementation of these functions.

@CLAassistant
Copy link

CLAassistant commented Apr 28, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@buildbreaker buildbreaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reasonable add. Thanks for your help @kohenkatz !

@buildbreaker buildbreaker merged commit 0407823 into connectrpc:main May 15, 2023
@kohenkatz kohenkatz deleted the add-responsemessage-extensions branch May 16, 2023 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants