Last active
July 31, 2023 18:59
-
-
Save sdetilly/287fc691bd5992acb19ae355bf85c6b4 to your computer and use it in GitHub Desktop.
RestaurantFinder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun restaurantsNearUser(): Flow<List<Restaurant>> = | |
| flow { | |
| emit(null) | |
| gpsService.currentUserLocation().also { location -> | |
| emit(location) | |
| } | |
| } | |
| .map { userLocation -> | |
| buildRestaurantList(userLocation) | |
| } | |
| .distinctUntilChanged() // we won't notify observers if the list hasn't changed | |
| .flowOn(Dispatchers.Default) // All sorting work will be done in a non-UI Thread | |
| // Here, we can build the restaurant list from our Restaurant data | |
| // For example, if userLocation is null, then the list is unsorted | |
| // If userLocation is non-null, then we can sort the list so that closer restaurants appear on top | |
| fun buildRestaurantList(userLocation: GPSCoordinates?): List<Restaurant> { | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment