flowOf() 함수
lisfOf()
처럼 사용할 수 있음suspend fun main() {
flowOf(1, 2, 3, 4, 5)
.collect { print(it) } // 12345
}
emptyFlow() 함수
emptyList()
함수와 비슷suspend fun main() {
emptyFlow<Int>()
.collect { print(it) } // 아무것도 출력되지 않음
}
asFlow() 함수
Iterable
, Iterator
, Sequence
를 Flow로 변환suspend fun main() {
listOf(1, 2, 3, 4, 5)
// 또는 setOf(1, 2, 3, 4, 5)
// 또는 sequenceOf(1, 2, 3, 4, 5)
.asFlow()
.collect { print(it) } // 12345
suspend 함수를 Flow로 변환
suspend fun main() {
val function = suspend {
delay(1000)
"UserName"
}
function.asFlow() // 이렇게 변환 가능!
.collect { print(it) }
}
// (1초 후)
// UserName