This file contains 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
/** | |
* Will wait at least [duration] for first item. | |
*/ | |
fun <T> Flow<T>.waitAtLeast(duration: Duration): Flow<T> = | |
combine(flow { delay(duration); emit(Unit) }) { value, _ -> value } |
This file contains 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
package com.advancedrecoverysystems.nobu.mvi | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.viewModelScope | |
import kotlinx.coroutines.channels.Channel | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.StateFlow | |
import kotlinx.coroutines.flow.asStateFlow | |
import kotlinx.coroutines.flow.consumeAsFlow |
This file contains 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 main() { | |
val obj: Any = "TGIK!" | |
// obj es convertido automaticamente a String en el lado derecho de `||` | |
if (obj !is String || obj.length == 0) return | |
// obj es convertido automaticamente a String en el lado derecho de `&&` | |
if (obj is String && obj.length > 0) { | |
println(obj.length) // obj es convertido automaticamente a String | |
} |
This file contains 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 getStringLength(obj: Any): Int? { | |
if (obj is String) { | |
// `obj` se convierte automaticamente a `String` en este bloque | |
return obj.length | |
} | |
// `obj` aun es de tipo `Any` afuera del cuerpo del `if` | |
return null | |
} |
This file contains 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 main() { | |
val obj: Any = "Kotlin!" | |
if (obj is String) { | |
println("obj es un String") | |
} | |
} |
This file contains 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
function getStringLength(obj) { | |
if (typeof obj === 'string' && obj.length > 0) { | |
return obj.length; | |
} | |
return null; | |
} |
This file contains 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
public final class AutomaticCasts { | |
@Nullable | |
public static final Integer getStringLength(@NotNull Object obj) { | |
Intrinsics.checkParameterIsNotNull(obj, "obj"); | |
return obj instanceof String && ((String)obj).length() > 0 ? ((String)obj).length() : null; | |
} | |
} |