groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Milles, Eric (TR Technology & Ops)" <eric.mil...@thomsonreuters.com>
Subject DGM for first or default
Date Thu, 18 Oct 2018 15:39:55 GMT
I see there are the following DGMs for getting first element of a "collection":

  static <T> T first(T[] self)

  static <T> T first(List<T> self)

  static <T> T first(Iterable<T> self)


Is there a simple sequence for getting the first element or a default value if the "collection"
is empty?  If not, may I propose the addition of the following DGMs:

  static <T> T first(T[] self, T defaultValue)

  static <T> T first(List<T> self, T defaultValue)

  static <T> T first(Iterable<T> self, T defaultValue)

  static <T> T first(T[] self, Closure<T> defaultSupplier)
  static <T> T first(List<T> self, Closure<T> defaultSupplier)

  static <T> T first(Iterable<T> self, Closure<T> defaultSupplier)



Eric M.

Mime
View raw message