dave08
02/05/2020, 4:57 PMFlow without having to use toList().last() ...?jw
02/05/2020, 4:59 PMsuspend fun <T> Flow<T>.last(): T? {
var last: T? = null
collect {
last = it
}
return last
}dave08
02/05/2020, 5:00 PMjw
02/05/2020, 5:01 PMsuspend fun <T> Flow<T>.last(): T {
val marker = Any()
var last: Any? = marker
collect {
last = it
}
if (last === marker) throw NoSuchElementException()
return last as T
}jw
02/05/2020, 5:01 PMdave08
02/05/2020, 5:03 PMAny() could be instantiated and used like that... also good to know!