Optional.asSet

Remi Forax forax at univ-mlv.fr
Mon Jun 24 01:16:09 PDT 2013


This is something that was lost among the other issues but
I think that it's useful to sometime see Optional as a Collection (with 
a size, etc),
given that Guava's Optional has a method asSet, I think JDK's Optional 
should have
the same method.

public Set<T> asSet() {
    if (isPresent()) {
      return Collections.singleton(value);
    }
    return Collections.emptySet();
}

cheers,
Rémi



More information about the lambda-libs-spec-observers mailing list