Closed romtsn closed 6 years ago
My general problem with this is that the majority of APIs accepting some kind of callback or lambda do not provide the enclosing instance and we would have to apply this trick to all of them.
The traditional Kotlin pattern for solving this is to create a scope with the instance you want to re-use with let
:
binding.included.toolbar.let { toolbar ->
toolbar.post { toolbar.subtitle = "something" }
}
Good point, also with
is a good candidate for this. Just thought that the post
is the most usable thing, which could've had such an extension to ease the usage for those, who is not aware of scoping functions/doesn't want to use them for reasons.
Sometimes it's tedious to call a
post
method on someView
object, and then access this object again inside the braces, especially with databinding. For example:If we'd have a following extension, it could make it a little bit easier: