Ellen Spertus
04/07/2020, 9:33 PMType mismatch
error in this code?
private fun applyIfPossible(contacts: List<ContactEntity>): Unit {
contacts.firstOrNull() ?.run { contact ->
println(contact)
}
}
Shawn
04/07/2020, 9:37 PMrun
is scoped such that the context object in the lambda it accepts is this
, i.e. T.()
rather than (T)
, or accepts TShawn
04/07/2020, 9:38 PMShawn
04/07/2020, 9:38 PMcontact ->
and instead println(this)
, it’ll workEllen Spertus
04/07/2020, 9:38 PMEllen Spertus
04/07/2020, 9:39 PMCasey Brooks
04/07/2020, 9:39 PM.let{ }
would be equivalent to what you’re wanting (a named parameter passed to the lambda)Shawn
04/07/2020, 9:39 PMlet
or also
hereCasey Brooks
04/07/2020, 9:41 PMEllen Spertus
04/07/2020, 9:42 PMlet
, also
, run
, etc. I made myself a table of whether they use `it`/`this` and what they return, but the differences seem to run deeper.Ellen Spertus
04/07/2020, 9:42 PMShawn
04/07/2020, 9:48 PMEllen Spertus
04/07/2020, 9:48 PMShawn
04/07/2020, 9:49 PMShawn
04/07/2020, 9:49 PMShawn
04/07/2020, 9:49 PMShawn
04/07/2020, 9:50 PMShawn
04/07/2020, 9:50 PMShawn
04/07/2020, 9:51 PMrun
is overloadedShawn
04/07/2020, 9:51 PMEllen Spertus
04/07/2020, 9:51 PMShawn
04/07/2020, 9:52 PMI don’t expect you to do research for meno, totally, I get what you’re saying and I’m happy to dig into the archives a bit for someone making a good faith attempt to learn lol
Shawn
04/07/2020, 9:52 PMEllen Spertus
04/07/2020, 9:53 PMrocketraman
04/07/2020, 10:22 PMrocketraman
04/07/2020, 10:25 PMAlexey Belkov [JB]
04/10/2020, 1:59 PM