In Java, I have recently began to adopt the Optional type more in my code. This allows for better null-value handling and to some extend also safer code. Optional has the ifPresentOrElse method which allows you to perform a specific action for when a value is present, or a specific action for when no value is present. However, this method does not allow you to declare a return type.
Is there an easy way I can use optionals and a ifPresentOrElse-like method to return values while unwrapping an Optional?