Is this style of using apply and run recommended? ...
# announcements
s
Is this style of using apply and run recommended?
Copy code
IntentFilter().apply {
                addAction( packageName +  INTENT_ACTION_OPEN )
                addAction( packageName +  INTENT_ACTION_CLOSE )
            }.run {
                registerReceiver( receiver, this )
            }
d
I would do,
Copy code
registerReceiver(receiver, IntentFilter().apply {
                addAction( packageName +  INTENT_ACTION_OPEN )
                addAction( packageName +  INTENT_ACTION_CLOSE )
            })
s
Sure
So is chaining scope functions not a thing?
d
It is but I wouldn't use it in this case.
s
Got it, your version is more readable too
d
If you were calling
registerReceiver
twice for example, then I would chain.
s
Ok
which is seldom the case, usually it is like to build something and to pass it to a function
notificaiton builder and pass to notification service etc
d
Yeah.