https://kotlinlang.org logo
Title
l

Lukasz Kalnik

07/01/2022, 3:11 PM
Is there some clever way in Arrow to check a list of nullable values if any of them
!= null
Apart from the standard syntax:
myVal1 != null || myVal2 != null || myVal3 != null
This is ok, but I would like to write something more expressive, like:
listOf(myVal1, myVal2, myVal3).anyNotNull()
Do I have to use
Option
for this?
a

Alejandro Serrano Mena

07/01/2022, 3:16 PM
listOf(myVal1, myVal2, myVal3).any { it != null }
would work
l

Lukasz Kalnik

07/01/2022, 3:16 PM
Oh yes, that's quite simple 😄
Thank you!
a

Alejandro Serrano Mena

07/01/2022, 3:16 PM
my pleasure!
also
listOfNotNull(myVal1, myVal2, myVal3).isNotEmpty()
could work
l

Lukasz Kalnik

07/01/2022, 3:17 PM
I think the first one is clearer for the reader at first glance