/** * Get an empty optional in case of failure. * * @return An empty optional in case of failure. */ public Optional<V> toOptional() { return isFailure() ? Optional.empty() : Optional.ofNullable(get()); }
/** * Flat map the success value. * * @param mapper Mapper. * @param <T> New type. * @return A new try value for success or failure. */ public <T> Value<T> flatMap(Throwing.Function<V, Value<T>> mapper) { if (isFailure()) { return (Value<T>) this; } try { return mapper.apply(get()); } catch (Throwable x) { return new Failure<>(x); } }