Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8214753

(opt) add Optional::transform, allowing an arbitrary operation on an Optional

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • None
    • core-libs
    • None

    Description

      Add a method something like this to Optional:

          public <R> R transform(Function<Optional<T>, ? extends R> f) {
              return f.apply(this);
          }

      This allows the caller to provide an arbitrary operation to be performed on "this" Optional, regardless of whether it's empty or present. The name "transform" follows precedent set by String::transform (JDK-8203442).

      Attachments

        Issue Links

          Activity

            People

              smarks Stuart Marks
              smarks Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: