Is this ridiculous or useful?
# codereview
c
Is this ridiculous or useful?
👎 1
d
Copy code
fun functionalDecision(worker:Worker?) {
    worker?.apply {
        doSomeThing()
    } ?: println("We have a problem")
}
Although, I find that both hard to read.
t
I would say no to an
ifApply
due to already having
?.apply
and generally I try to avoid using elvis as a control flow for anything other than a trivial case. ie
?: throw SomeDetailException() // as opposed to just using a !!
c
Would you just do normal if else? Typically the else cases may be more than a single statement. Scenario I tried to find something in a database. If I find it I want to update it. If it doesn't exist I want to create new one. I want to log as well. Or is this a case where those should be separate functions themselves?
t
Yeah if else usually for me. A trained kotlin eye is probably fine with fancy Elvis use but anybody can follow normal if else. Then multiple functions if it fits I guess
c
This will do just as well. 🤦
r
Yea I think if else is just fine. and there already a elvis operate if null. So adding extension functions might not be worth it