Skip to content

Instantly share code, notes, and snippets.

@gpeal
Created March 5, 2022 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpeal/cfdf5a55c4bc3de8b32c29a156a79385 to your computer and use it in GitHub Desktop.
Save gpeal/cfdf5a55c4bc3de8b32c29a156a79385 to your computer and use it in GitHub Desktop.
Anvil Simple Use Case
@Singleton
class LocationProvider @Inject constructor() {
suspend fun currentLocation(): Pair<Float, Float> = 123.456f to 789.012f
}
class WeatherApi @Inject constructor() {
suspend fun getWeather(latLng: Pair<Float, Float>): Float = 72f
}
class WeatherUseCase @Inject constructor(
private val locationProvider: LocationProvider,
private val weatherApi: WeatherApi,
) {
suspend fun getWeather(): Float {
val location = locationProvider.currentLocation()
return weatherApi.getWeather(location)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment