Mohamed Ibrahim
06/10/2019, 9:29 AMmodel?.let{ some code} ?: run { code in case model is null}
gildor
06/10/2019, 9:30 AMif (model != null) { some code } else { code in case model is null }
tipsy
06/10/2019, 9:35 AMlet
and ?:
for cases where `if`/`else` are much better fitsPavlo Liapota
06/10/2019, 9:36 AMrun
will be executed if model
is `null`or if some code
in let
will return null
.gildor
06/10/2019, 9:38 AMtrue, which make it even more confusinginsome code
will returnlet
null
val someResult = if (model != null) { some code } else null
if (someResult == null) {
//code in case model or result is null
}
Stephan Schroeder
06/10/2019, 10:35 AMJessie
06/10/2019, 3:32 PMlet
operator when data could have changed in runtime, and also compiler doesn’t allow to have an if/else
, so that’d be a good idea IMO, use let operator when an if/else
is not allowed.rook
06/10/2019, 3:54 PMlet
to wrap mutable variables. But it’s kind of unclear from the sample whether that’s happening.gildor
06/10/2019, 3:56 PMto wrap Mutable variables
val immutable = mutable
rook
06/10/2019, 4:03 PMsomeMutable?.let {
//lock state and do work
}
/*now I don't have another thing hanging around representing old state*/
gildor
06/10/2019, 4:28 PM