nkiesel
02/16/2021, 11:52 PMval port = property.getProperty("notification.port").orEmpty().let { if (it.isNotBlank()) it else "7100"}
? Is there something like ``val port = firstContent(property.getProperty("notification.port"), "7100")` ?ilya.gorbunov
02/16/2021, 11:59 PMproperty.getProperty("notification.port")?.ifBlank { null } ?: "7100"
?nkiesel
02/17/2021, 12:08 AMgetProperty
is a Java function which returns a String?
. I was looking for something like String?.isNotNullOrBlankOrElse(def: String): String
(obviously with a better name).nkiesel
02/17/2021, 12:16 AMfun String?.contentOrElse(def: String) = if (isNullOrBlank()) def else this
I could write val port = property.getProperty("notification.port").contentOrElse("7100")
. But such a function does not exists in the Kotlin stdlib, does it?Saharath Kleips
02/17/2021, 12:16 AMproperty.getProperty("notification.port")?.takeIf { it.isNotBlank() } ?: "7100"
?nkiesel
02/17/2021, 12:17 AMifBlank { null }
approach, thx.Saharath Kleips
02/17/2021, 12:18 AM?.takeIf(String::isNotBlank)
nanodeath
02/17/2021, 12:18 AM?.toIntOrNull()
call in therenkiesel
02/17/2021, 12:22 AM?.takeIf(String::IsNotBlank)
. This looks pretty readable and this takeIf
approach is more general than my contentOrElse
because I could do e.g. ?.takeIf { it.length > 3 } ?: "longEnough"
nkiesel
02/17/2021, 12:24 AMString
and not Int
Hullaballoonatic
02/17/2021, 12:28 AMmost are actuallyhi, my name is javascript, and these are the same thingand notString
Int
nkiesel
02/17/2021, 12:31 AM