Is there an elegant way to add something to map on...
# announcements
j
Is there an elegant way to add something to map only if it’s not null? code below won’t compile
Copy code
mapOf(
  LIST_ID to listId,
  eventId?.let { EVENT_ID to eventId }
)
o
My initial thinking is to filter out your null event IDs first then chain it with a map or something so you know you are mapping only non-null values . I'm not sure if there's a way to inline what you're saying into that mapOf operation to skip over nullable values
m
Copy code
listOfNotNull(
    LIST_ID to listId,
    eventId?.let{ EVENT_ID to eventId }
).toMap()
although it's weird that there is a
listOfNotNull
function, but not a
mapOfNotNull
☝️ 4
o
Good find! That's dope