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 support for typed exception handling in suppliers to improve forComp useability #15

Open
Alex-At-Home opened this issue Jun 22, 2016 · 0 comments

Comments

@Alex-At-Home
Copy link

One really annoying thing in J8 is that there's no way of passing up typed exceptions, so if you have a long pipeline of lambdas calling functions that can throw them, you end up having to wrap the nice 1-liners in horrible try/catch routines.

I wrote a bunch of simple utilities to convert lambda to untyped exceptions here (eg): https://github.com/Alex-At-Home/Aleph2/blob/master/aleph2_data_model/src/com/ikanow/aleph2/data_model/utils/Lambdas.java#L64

So eg you'd do forComp(a, Utils.wrap(() -> FileUtils.openFile(...)))

One thing you could do in Halva specifically to help with for comprehensions is provide a similar util throwing an (untyped) LambdaException, and then catch those in the forComp code and have a Optional<LambdaException> For.pipelineError / or make it throw err.getCause() / whatever a sensible response to the error would be? (Could specify the policy with like forComp(..).ignoreErrors().etc or forComp(..).throwOnError().etc)

(In the general "monadic for" case you could also specify what to do with an error, eg make Optional become empty, switch a Validation to fail)

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

No branches or pull requests

1 participant