Utilities and functions for checking and casting values in optionals and streams.

Description

Sometimes it's useful to check if an optional is of a particular type, and if so retrieve that value cast to the appropriate type. We can do this already with a filter+map operation like this:

Still it would be nice in some situations to have something simpler.

We also have an Optionals.asInstance() method already which performs a similar operation on a nullable value. And in fact we could use that utility in a flat map operation on someOptional above. Still it might be handy to have this extra compact way of doing things in certain situations. Approaches for doing this with streams would probably be helpful as well.

Environment

None

Assignee

Garret Wilson

Reporter

Garret Wilson

Labels

None

Fix versions

Priority

Minor
Configure