Skip to content

Instantly share code, notes, and snippets.

@NikolaDespotoski
Created July 23, 2019 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NikolaDespotoski/62e631fb43aea3fa02b333939aa28851 to your computer and use it in GitHub Desktop.
Save NikolaDespotoski/62e631fb43aea3fa02b333939aa28851 to your computer and use it in GitHub Desktop.
Kotlin Flows last operator
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