public static <T, O> Collector<T, ?, O> toOptional(Supplier<O> empty, Function<T, O> factory) {
        return Collector.of(
            () -> new OptionalBuilder<>(empty, factory),
            OptionalBuilder::set,
            OptionalBuilder::combine,
            OptionalBuilder::build);
    }
Returns a {@code Collector} that accumulates 0 or 1 input elements into an arbitrary
optional-style container type. The returned collector will throw
{@code IllegalStateException} whenever 2 or more elements are present in a stream. Null elements
are mapped to an empty container.

@param empty   Supplies an instance of the optional type with no value.
@param factory Returns an instance of the optional type with the input parameter as the value.
@param <T>     The optional element type.
@param <O>     The optional type, which may incorporate the {@code T} generic parameter e.g.
               {@code Optional<T>}.
@return a {@code Collector} which collects 0 or 1 input elements into an arbitrary
optional-style container type.
core/src/main/java/org/jdbi/v3/core/collector/OptionalCollectors.java