Created
July 23, 2019 08:32
-
-
Save NikolaDespotoski/62e631fb43aea3fa02b333939aa28851 to your computer and use it in GitHub Desktop.
Kotlin Flows last operator
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
public fun <T> Flow<T>.last(): Flow<T> = flow { | |
try { | |
var last : Any? = null | |
collect { value -> | |
last = value | |
} | |
emit(last as T) | |
} catch (e: Throwable) { | |
// Nothing, bail out | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment