I want to use let to check two conditions
Lets say if I had to use if then this is the condition
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
Any help will be highly appreciated
For your specific case you could use takeIf
it.data
   ?.takeIf { data ->  data.name.isNotEmpty() }
   ?.let { data -> ...}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With