public T orElseDoAndReturnDefault ( Consumer < Result < T > > consumer , T defaultVal ) { if ( isSuccessAndNotNull ( ) ) { return data ; } consumer . accept ( this ) ; return defaultVal ; }
The consumer function receives the entire result object as parameter in case you want to log or manage the error message or code in any way .