1. Flow 생성

fun main() = runBlocking {

    val flow1 = (0..10).asFlow()

    println("flow1")
    flow1.collect {
        delay(400)
        print("$it ")
    }

    println("\\nflow2")
    flowOf(1, 2, 3, 4, 5).collect {
        delay(400)
        print("$it ")
    }

		val flow3 = flow {
        (0..5).forEach {
            emit(it)
        }
    }

    println("\\nflow3")
    flow3.collect {
        delay(400)
        print("$it ")
    }

}
flow1
0 1 2 3 4 5 6 7 8 9 10 
flow2
1 2 3 4 5
flow3
0 1 2 3 4 5

1-1. map

fun main() = runBlocking {
    (1..10).asFlow()
        .map {
            it * it
        }
        .collect {
            print("$it ")
        }
}
1 4 9 16 25 36 49 64 81 100

1-2. filter

fun main() = runBlocking {
    (1..10).asFlow()
        .filter {
            it % 2 == 0
        }
        .collect {
            print("$it ")
        }

}