Isn't it equivalent to something like this?
|def elem = collection?.first()?: defaultValue||
||def elem = collection?.first()?: defaultSupplier()||
|
Mauro
Il 18/10/2018 17:39, Milles, Eric (TR Technology & Ops) ha scritto:
I see there are the following DGMs for getting first element of
a "collection":
static<T>Tfirst(T[] self)
static<T>Tfirst(List<T>self)
static<T>Tfirst(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>Tfirst(T[] self, TdefaultValue)
static<T>Tfirst(List<T>self, TdefaultValue)
static<T>Tfirst(Iterable<T>self, TdefaultValue)
static<T>Tfirst(T[] self, Closure<T> defaultSupplier)
static<T>Tfirst(List<T>self, Closure<T> defaultSupplier)
static<T>Tfirst(Iterable<T>self, Closure<T> defaultSupplier)
Eric M.