Method chain replacement for Optional.ifPresentOrElse()

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P4
    • None
    • Affects Version/s: 14
    • Component/s: core-libs

      A DESCRIPTION OF THE PROBLEM :
      Optional's new ifPresentOrElse() method is an improvement over the previous if/else idioms used for Optional, but it is somewhat clunky to declare your "ifPresent" logic after the language "orElse". E.g.,

      optional.ifPresentOrElse(System.out::println, System.out::println);

      If, instead, you could chain off the result of ifPresent(), it would result in much more fluid code:

      optional.ifPresent(System.out::println).orElse(System.out::println);

      This could be accomplished by making ifPresent() return itself and adding an orElse() method to optional, or by adding a new return type to ifPresent() specifically for chaining.


            Assignee:
            Paul Sandoz
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: