groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mauro Molinari <mauro...@tiscali.it>
Subject Re: DGM for first or default
Date Thu, 18 Oct 2018 16:51:22 GMT
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.
>


Mime
View raw message