michaelbull / kotlin-result

A multiplatform Result monad for modelling success or failure operations.
ISC License
1.05k stars 63 forks source link

Best practices for integrating with Flow<T> #80

Closed Gregory991 closed 2 years ago

Gregory991 commented 2 years ago

I'm not really sure the best way to achieve this. It could very well be ignorance on my part.

I have an Android room table i want to Flow on. Something like:Flow<Vehicle> First i need to get the userVehicleId from the User Repository. That isn't a flow, it returns Result<Int, Unit>

The function i have atm looks like this:

suspend fun getUserVehicle(): Flow<Result<Vehicle, Unit>>{ 
   return userRepo.getUserVehicle()              // returns `Result<Int, Unit> `
        .andThen{ id ->
            Ok(vehicleDao.flowOnUserVehicle(id)) // returns Flow<Vehicle, Unit>
        }
}

This isn't valid and won't compile. Since I'm returning Result<Flow<Vehicle, Unit>

Thanks in advance!

michaelbull commented 2 years ago

Thanks for your report. We have an active discussion on extensions for kotlin's Flow type in https://github.com/michaelbull/kotlin-result/issues/78. Feel free to add any ideas or problems you are facing in that thread.

Closing as duplicate.