I want to use let to check two conditions Lets say if I had to use if then this is the condition
let
if
if (it.data != null && !it.data!!.name.isEmpty()) {}
How can I convert it to use let I know that to check null this is what we do
it.data?.let {}
but I don't know how to check the second part which is if a string is empty or not. Please keep in mind that I have to check that data is not null AND data.name is not empty
data
data.name
Any help will be highly appreciated
For your specific case you could use takeIf
takeIf
it.data ?.takeIf { data -> data.name.isNotEmpty() } ?.let { data -> ...}
1.4m articles
1.4m replys
5 comments
57.0k users