rootandy
03/06/2018, 8:05 AMgildor
03/06/2018, 8:05 AMguard
Loránd
03/06/2018, 8:06 AMif ( foo?.first?.second?.third?.fourth?.fifth != null ) {
}
in this case i will have to type that out if i want to use it in the block, of course i can create a property outside to store it but i just think this is much nicer.
if ( val foo1 = foo?.first?.second?.third?.fourth?.fifth ){
}
gildor
03/06/2018, 8:07 AMgildor
03/06/2018, 8:07 AMif
.
val foo1 = foo?.first?.second?.third?.fourth?.fifth ?: return
foo1.doSomething()
Not really universal, but works for some casesLoránd
03/06/2018, 8:08 AMgildor
03/06/2018, 8:09 AMgildor
03/06/2018, 8:10 AMgildor
03/06/2018, 8:12 AMval foo1 = foo?.first?.second?.third?.fourth?.fifth
if (foo1 != null) {
foo1.doSomething()
} else {
otherStuff()
}
Yes, one line more, but still not sure that this much better:
if (val foo1 = foo?.first?.second?.third?.fourth?.fifth) {
foo1.doSomething()
} else {
otherStuff()
}
One line less and scoped foo1, not so bad.ribesg
03/06/2018, 8:13 AMgildor
03/06/2018, 8:13 AMLoránd
03/06/2018, 8:18 AMelse
clause on the .let {}
would suffice in my oppinion.ribesg
03/06/2018, 8:20 AMelse
on a normal `.let{}`do?gildor
03/06/2018, 8:21 AMlet
is not nullability checking function and else
for this case is really bad solution
let
is like map
for single value + scopingribesg
03/06/2018, 8:21 AMLoránd
03/06/2018, 8:24 AMcedric
03/06/2018, 8:35 AMebonet
03/06/2018, 8:40 AMkarelpeeters
03/06/2018, 8:44 AMforEach
.gildor
03/06/2018, 8:46 AMNo refactoring suggestion for me▾
karelpeeters
03/06/2018, 8:48 AMthemishkun
03/06/2018, 8:50 AMgildor
03/06/2018, 8:52 AMfor
or pure forEach
, and with collection operators like list.filter().map{}
forEach looks better, because you just chain itedwardwongtl
03/06/2018, 8:53 AMforEach
? IMO they are both readable, just in imperative aspect or functional aspectspand
03/06/2018, 9:01 AMDavor
03/06/2018, 9:18 AMDavor
03/06/2018, 9:19 AMDavor
03/06/2018, 9:19 AMDavor
03/06/2018, 9:20 AMdroidrcc
03/06/2018, 10:56 AM