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

Adding in ErrorProjection concept #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cmbaxter
Copy link

@cmbaxter cmbaxter commented Sep 12, 2019

This borrows from the concept of a FailureProjection on the Validation type from scalaz. Adding this ErrorProjection concept allows one to map or flatMap over error cases and then force back to the main Result type.

Also made some updates and deprecations to existing methods:

  • Deprecated mapOk and flatMapOk in favor of just map and flatMap since it should be implied now that mapping and flatMapping should be for the Ok case only.
  • Hooked the pre-existing mapErr into error().map(...) instead now that that exists
  • Deprecated mapErr since it can be expressed now via error().map(...)

Copy link

@itscharlieb itscharlieb left a comment

Choose a reason for hiding this comment

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

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);

Choose a reason for hiding this comment

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

could this be written more succinctly as

Result<...> nestedResult = result.match(mapper, Result::ok);

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.

2 participants