You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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)
The text was updated successfully, but these errors were encountered:
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 aOptional<LambdaException> For.pipelineError
/ or make it throwerr.getCause()
/ whatever a sensible response to the error would be? (Could specify the policy with likeforComp(..).ignoreErrors().etc
orforComp(..).throwOnError().etc
)(In the general "monadic for" case you could also specify what to do with an error, eg make
Optional
becomeempty
, switch aValidation
tofail
)The text was updated successfully, but these errors were encountered: