is there a function analogical to `let` but for em...
# stdlib
r
is there a function analogical to
let
but for empty strings
someString?.let { calculate(it) }
I need
someString.doIfNotEmpty { calculate(it) }
?
c
If I have to do that often, I usually define one like this:
Copy code
private inline fun String?.doIfNotEmpty(block: (String) -> Unit) {
	this?.takeIf(String::isNotEmpty)?.let { block(it) }
}
Note, I'm treating
null
as empty here, if your usage is different, you may have to account for that.
👍 1
k
?.let(block)
😉