This blog post started with a simple problem in my Java-based application: I’ve got an API access token and I want to return the associated API client identity if it is valid, or no identity otherwise. Lo, it is no longer 2013 and we’ve got Optional exactly for this purpose! So we had aOptional getIdentityForValidToken(Token token) function, and for a time, it was good.

Then more validation rules came and the need to propagate the reason why a token was rejected to the caller with them. Optional can only be present or absent but does not give any explanation.

#optionals #exception #programming #java #either

Reasonable Optional or Either?
1.35 GEEK