public static <R> Optional<R> supplierIfTrue(boolean bool,
            Supplier<R> supplier) {
        return bool ? Optional.ofNullable(supplier.get()) : Optional.empty();
    }
public static < R > Optional < R > supplierIfTrue ( boolean bool , Supplier < R > supplier ) { return bool ? Optional . ofNullable ( supplier . get ( ) ) : Optional . empty ( ) ; }
Supplier if true optional.

@param <R>      the type parameter
@param bool     the bool
@param supplier the supplier
@return the optional