Open
Conversation
itscharlieb
reviewed
Sep 12, 2019
itscharlieb
left a comment
There was a problem hiding this comment.
Cool I think this is nifty, but no real strong preference for this vs flatMapOk, will leave that up to others with strong FP convictions
| } | ||
|
|
||
| public <RERR_TYPE> ErrorProjection<SUCC_TYPE, RERR_TYPE> flatMap(Function<ERR_TYPE, Result<SUCC_TYPE, RERR_TYPE>> mapper) { | ||
| Result<SUCC_TYPE, Result<SUCC_TYPE, RERR_TYPE>> nestedResult = Results.<SUCC_TYPE, ERR_TYPE, Result<SUCC_TYPE, RERR_TYPE>>modErr(mapper).apply(result); |
There was a problem hiding this comment.
could this be written more succinctly as
Result<...> nestedResult = result.match(mapper, Result::ok);
zklapow
requested changes
May 7, 2025
Member
zklapow
left a comment
There was a problem hiding this comment.
TBH my pref would be to simply leave this API alone. I see how error().map() could maybe read better but this seems to add a bunch of complexity (and leave us with 2 apis?) to achieve that vs just calling mapErr etc which are more discoverable? Maybe I am missing something here about why this API is nicer tho.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This borrows from the concept of a
FailureProjectionon theValidationtype from scalaz. Adding thisErrorProjectionconcept allows one tomaporflatMapover error cases and then force back to the mainResulttype.Also made some updates and deprecations to existing methods:
mapOkandflatMapOkin favor of justmapandflatMapsince it should be implied now that mapping and flatMapping should be for the Ok case only.mapErrintoerror().map(...)instead now that that existsmapErrsince it can be expressed now viaerror().map(...)