public <R> StreamEx<R> mapPartial(Function<? super T, ? extends Optional<? extends R>> mapper) {
        return new StreamEx<>(stream().map(value -> mapper.apply(value).orElse(null)).filter(Objects::nonNull),
                context);
    }
public < R > StreamEx < R > mapPartial ( Function < ? super T , ? extends Optional < ? extends R > > mapper ) { return new StreamEx < > ( stream ( ) . map ( value -> mapper . apply ( value ) . orElse ( null ) ) . filter ( Objects :: nonNull ) , context ) ; }
Performs a mapping of the stream content to a partial function
removing the elements to which the function is not applicable.

<p>
If the mapping function returns {@link Optional#empty()}, the original
value will be removed from the resulting stream. The mapping function
may not return null.

<p>
This is an <a href="package-summary.html#StreamOps">intermediate
operation</a>.

<p>
The {@code mapPartial()} operation has the effect of applying a
one-to-zero-or-one transformation to the elements of the stream, and then
flattening the resulting elements into a new stream.

@param <R> The element type of the new stream
@param mapper a <a
href="package-summary.html#NonInterference">non-interfering </a>,
<a href="package-summary.html#Statelessness">stateless</a>
partial function to apply to each element which returns a present optional
if it's applicable, or an empty optional otherwise
@return the new stream
@since 0.6.8