DefaultIfEmpty can cover:
def list = []
def defaultIfEmpty = list ?: [ 'was empty' ]
FirstOrDefault more complicated, since I believe that it returns the default value for the given type if the list does not have the first element ... However, in Groovy (as it is) there is no way to detect the type of the object by default (if it is not native)
You can do:
Integer defaultIfEmpty = list[ 0 ] ?: 0
It should be noted that the truthelvis operator ?: works on Groovy , therefore, if the element to the left of the operator evaluates to false in Groovy (be it nullan empty list or line, number 0, etc.), it will return the right side)
, .NET, .