https://kotlinlang.org logo
#android
Title
# android
a

althaf

11/08/2023, 6:53 AM
Hi i couldn't find a #kotlin channel so asking here
Copy code
override suspend fun saveToDeviceRegistry(req: SaveToDeviceRegistryReq): Flow<RepositoryState<Unit>> =
    flow<RepositoryState<Unit>> {
        searchDeviceRegistryByCategoryId(req.deviceProfile.categoryId)?.let {
            it.categoryName = req.deviceProfile.categoryName
            it.categoryId = req.deviceProfile.categoryId
            it.vendor = req.deviceProfile.vendor
            it.model = req.deviceProfile.model
            it.mac = req.deviceProfile.address
            deviceRegistryBox.put(it)
            emit(RepositoryState.SuccessState(Unit))
        } ?: kotlin.run {
            deviceRegistryBox.put(
                DeviceRegistryEntity(
                    categoryName = req.deviceProfile.categoryName,
                    categoryId = req.deviceProfile.categoryId,
                    vendor = req.deviceProfile.vendor,
                    model = req.deviceProfile.model,
                    mac = req.deviceProfile.address,
                )
            )
            emit(RepositoryState.SuccessState(Unit))
        }
    }.flowOn(dispatcher)
Is there a better syntax sugar for the above code scenario ?
k

kenkyee

11/08/2023, 3:16 PM
This entire slack is about Kotlin. You probably should post this in #getting-started
a

althaf

11/08/2023, 3:43 PM
@kenkyee thank you 🙂