https://kotlinlang.org logo
Title
s

Sam

10/04/2018, 8:53 PM
Is this style of using apply and run recommended?
IntentFilter().apply {
                addAction( packageName +  INTENT_ACTION_OPEN )
                addAction( packageName +  INTENT_ACTION_CLOSE )
            }.run {
                registerReceiver( receiver, this )
            }
d

Dominaezzz

10/04/2018, 9:05 PM
I would do,
registerReceiver(receiver, IntentFilter().apply {
                addAction( packageName +  INTENT_ACTION_OPEN )
                addAction( packageName +  INTENT_ACTION_CLOSE )
            })
s

Sam

10/04/2018, 9:06 PM
Sure
So is chaining scope functions not a thing?
d

Dominaezzz

10/04/2018, 9:07 PM
It is but I wouldn't use it in this case.
s

Sam

10/04/2018, 9:07 PM
Got it, your version is more readable too
d

Dominaezzz

10/04/2018, 9:09 PM
If you were calling
registerReceiver
twice for example, then I would chain.
s

Sam

10/04/2018, 9:10 PM
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

Dominaezzz

10/04/2018, 9:12 PM
Yeah.