01/13/2012. From a lecture by Professor John Ousterhout at Stanford, class CS140
Here's today's thought for the weekend. A little bit of slope makes up for a lot of Y-intercept.
[Laughter]
sealed interface Result<out T> { | |
data class Success<T>(val data: T) : Result<T> | |
data class Error(val exception: Throwable) : Result<Nothing> | |
data object Loading : Result<Nothing> | |
} | |
fun <T> Flow<T>.asResult(): Flow<Result<T>> = map<T, Result<T>> { Result.Success(it) } | |
.onStart { emit(Result.Loading) } | |
.catch { emit(Result.Error(it)) } | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.viewModelScope | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.SharingStarted | |
import kotlinx.coroutines.flow.StateFlow | |
import kotlinx.coroutines.flow.catch | |
import kotlinx.coroutines.flow.debounce | |
import kotlinx.coroutines.flow.distinctUntilChanged |
interface NetworkMonitor { | |
val isOnline: Flow<Boolean> | |
} | |
class NetworkMonitorImpl @Inject constructor( | |
@ApplicationContext private val context: Context, | |
@Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, | |
) : NetworkMonitor { | |
override val isOnline: Flow<Boolean> | |
get() = callbackFlow { |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.platform.LocalContext | |
import androidx.hilt.navigation.HiltViewModelFactory | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.ViewModelProvider | |
import androidx.lifecycle.ViewModelStoreOwner | |
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner | |
import androidx.lifecycle.viewmodel.compose.viewModel | |
import androidx.navigation.NavBackStackEntry |
# This is a basic workflow to help you get started with Actions | |
name: Publish to store | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the master branch | |
push: | |
branches: [ master ] | |
pull_request: |
FWIW: I'm not the author of the content presented here (which is an outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.
<string-array name="countries_array"> | |
<item>Afghanistan</item> | |
<item>Albania</item> | |
<item>Algeria</item> | |
<item>American Samoa</item> | |
<item>Andorra</item> | |
<item>Angola</item> | |
<item>Anguilla</item> | |
<item>Antarctica</item> | |
<item>Antigua and Barbuda</item> |