http://example.com
http://example.com
http://example.com
http://example.com
| private fun <K, V> Map<K, V>.mergeReduce(other: Map<K, V>, reduce: (V, V) -> V = { a, b -> b }): Map<K, V> { | |
| val result = LinkedHashMap<K, V>(this.size() + other.size()) | |
| result.putAll(this) | |
| other.forEach { e -> | |
| val existing = result[e.key] | |
| if (existing == null) { | |
| result[e.key] = e.value | |
| } | |
| else { |
| import org.junit.Test | |
| import org.assertj.core.api.Assertions | |
| import org.junit.BeforeClass | |
| class ThingTest { | |
| companion object { | |
| @JvmStatic | |
| @BeforeClass fun init() { |
| class CoroutineNamesTest { | |
| @Test fun coroutineNames() { | |
| runBlocking(CoroutineName("parent")) { | |
| println("parent: $coroutineContext") | |
| launch { | |
| println("unnamed child: $coroutineContext") | |
| } | |
| launch(CoroutineName("named child")) { |
In their most used version v4, UUIDs are random, and that's a useful property. But sometimes all you want is a UUID that is easy to remember. To hell with randomness!
A minor complication is that for a string to parse as a valid UUID, the variant and version bits should be set correctly (to 2 and 4, respectively). Here are a few suggestions that pass the test:
facade00-0000-4000-a000-000000000000
decade00-0000-4000-a000-000000000000
| /** | |
| * Starts collecting a flow when the lifecycle is started, and **cancels** the collection on stop. | |
| * This is different from `lifecycleScope.launchWhenStarted { flow.collect{...} }`, in which case | |
| * the coroutine is just suspended on stop. | |
| */ | |
| inline fun <reified T> Flow<T>.collectWhileStarted( | |
| lifecycleOwner: LifecycleOwner, | |
| noinline action: suspend (T) -> Unit | |
| ) { | |
| object : DefaultLifecycleObserver { |