bj0
01/16/2018, 4:25 AMwith to scope extension functions/properties defined in an object, but thats about alldave08
01/16/2018, 4:44 PMapply or similar?bj0
01/16/2018, 5:33 PMapply, I think it looks good and helps organization, but it's also the only way I know of to access extension methods that aren't top level. For example, in this BLE library, the following object contains some Service specific definitions: https://github.com/Beepiz/BleGattCoroutines/blob/master/genericaccess/src/main/java/com/beepiz/blegattcoroutines/experimental/genericaccess/GenericAccess.kt
and they are used like this: https://github.com/Beepiz/BleGattCoroutines/blob/master/common/src/main/java/com/beepiz/blegattcoroutines/sample/common/MainViewModel.kt#L30dave08
01/16/2018, 6:37 PMGenericAccess.apply { } doesn't work?dave08
01/16/2018, 6:38 PMapply is really more side effectish, whereas with is maybe clearer for main logic...bj0
01/16/2018, 6:39 PMCzar
01/16/2018, 6:57 PM.run instead of .apply to make it clear that I'm just using the scope and running some logic against it.bj0
01/16/2018, 7:07 PM.run since it become an extension function, but it seems equivalent to `with`:
MassTransferService.run {
enableReceiveBufferIndication()
}
with(MassTransferService) {
enableReceiveBufferIndication()
}bj0
01/16/2018, 7:08 PMwith in this particular case, it just reads more naturallybj0
01/16/2018, 7:10 PMenableReceiveBufferIndication() is not an extension function ON MassTransferService, it is defined within the service but acts on a different receiver object (GattConnection)bj0
01/16/2018, 7:11 PMGattConnectionCzar
01/16/2018, 7:39 PMdave08
01/16/2018, 7:41 PMapply sounds like you're changing the receiver...
@bj0 Where is that (not in what you referenced before)?bj0
01/16/2018, 8:10 PMGattConnection and I have several services on the connection, so I use with to scope them.bj0
01/16/2018, 8:11 PM