df
11/03/2020, 2:48 PMval foo = doSomething();
if (!foo) return;
and
val foo = doSomething() ?? return
would be nice.df
11/03/2020, 2:56 PMval items = repo.getPending()
if (items.isEmpty()) {
return
}
items.forEach { ... }df
11/03/2020, 2:57 PMdf
11/03/2020, 2:57 PMLuke
11/03/2020, 3:08 PMrepo.getPending().ifEmpty { return } work?Tobias Berger
11/03/2020, 3:08 PM!it.isEmpty() with it.isNotEmpty())
I personally prefer this to to the if check, but I guess that's just a style decision. Anyway, it combines a condition with the elvis operatorTobias Berger
11/03/2020, 3:11 PMtakeIf version can still be useful if you're checking a condition on something else.Nir
11/03/2020, 3:16 PMNir
11/03/2020, 3:16 PMNir
11/03/2020, 3:17 PMTobias Berger
11/03/2020, 3:18 PMdf
11/03/2020, 3:23 PMdf
11/03/2020, 3:24 PMNir
11/03/2020, 3:38 PMdoSomethingNir
11/03/2020, 3:38 PMdoSomething if doSomething itself decides to throwdf
11/03/2020, 3:55 PMdf
11/03/2020, 3:56 PMxxfast
11/03/2020, 4:00 PM? Stands for. In kotlin, question mark is always and exclusively for nullability notationRob Elliot
11/03/2020, 4:03 PMdf
11/03/2020, 4:09 PM