fun functionalDecision(worker:Worker?) {
worker?.apply {
doSomeThing()
} ?: println("We have a problem")
}
Dominaezzz
08/02/2019, 10:08 PM
Although, I find that both hard to read.
t
trevjones
08/02/2019, 10:32 PM
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
corneil
08/02/2019, 11:07 PM
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
trevjones
08/02/2019, 11:11 PM
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