What collections extension function can I use if I...
# announcements
v
What collections extension function can I use if I want to get first element from the list and if list is empty, then run a function that creates an element and returns it? The closest I found is
ifEmpty{}
, but it returns the entire collection if it is not empty, while I don’t need the collection and just it’s first element.
g
Copy code
list.getOrElse(0){ call function }
👍🏾 1
v
Looks like it is what I need. Thanks!