https://kotlinlang.org logo
#codereview
Title
# codereview
c

corneil

08/02/2019, 10:02 PM
Is this ridiculous or useful?
👎 1
d

Dominaezzz

08/02/2019, 10:07 PM
Copy code
fun functionalDecision(worker:Worker?) {
    worker?.apply {
        doSomeThing()
    } ?: println("We have a problem")
}
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
c

corneil

08/03/2019, 8:04 AM
This will do just as well. 🤦
r

rkeazor

08/03/2019, 2:15 PM
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
3 Views