Louis
12/12/2018, 10:46 AMval stringList = somethingList.map {
it.str
}
if (stringList.isNotEmpty()) {
doSomethingWithMyList(stringList)
}
And i would like to do something like that
somethingList.map {
it.str
}.unknownOperation { // here i need help
doSomethingWithMyList(it)
}
marstran
12/12/2018, 10:55 AMalso
?somethingList.map { it.str }
.also { doSomething(it) }
Louis
12/12/2018, 10:57 AM.also {
if (isNotEmpty()) {
doSomethingWithMyList(it)
}
}
but i just would like to know if there is an operator or another way to do the apply and if not emptyfun <T> List<T>.doIfNotEmpty(action: (List<T>) -> Unit): List<T> = also {
if (isNotEmpty()) {
action(this)
}
}
And i use it like
somethingList.map {
it.str
}.doIfNotEmpty { doSomethingWithMyList(it) }
I'm not sure it's the cleanest way to dogsala
12/12/2018, 1:10 PM.takeIf { it.isNotEmpty() }?.let{ doSomething(it)}
Louis
12/12/2018, 1:21 PM