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

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

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
      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

          Activity

            People

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

              Dates

              • Created:
                Updated: