@@ -44,12 +44,12 @@ import kotlin.jvm.*
44
44
* ```
45
45
* If you want to switch the context of execution of a flow, use the [flowOn] operator.
46
46
*/
47
- @ExperimentalCoroutinesApi
48
- public fun < T > flow (@BuilderInference block : suspend FlowCollector < T >.() -> Unit ): Flow < T > {
49
- return object : Flow < T > {
50
- override suspend fun collect ( collector : FlowCollector <T >) {
51
- SafeCollector (collector, coroutineContext).block()
52
- }
47
+ public fun < T > flow (@BuilderInference block : suspend FlowCollector < T >.() -> Unit ): Flow < T > = SafeFlow (block)
48
+
49
+ // Named anonymous object
50
+ private class SafeFlow < T >( private val block : suspend FlowCollector < T >.() -> Unit ) : Flow <T> {
51
+ override suspend fun collect (collector : FlowCollector < T >) {
52
+ SafeCollector (collector, coroutineContext).block()
53
53
}
54
54
}
55
55
@@ -90,7 +90,6 @@ public fun <T> (suspend () -> T).asFlow(): Flow<T> = unsafeFlow {
90
90
/* *
91
91
* Creates a flow that produces values from the given iterable.
92
92
*/
93
- @ExperimentalCoroutinesApi
94
93
public fun <T > Iterable<T>.asFlow (): Flow <T > = unsafeFlow {
95
94
forEach { value ->
96
95
emit(value)
@@ -100,7 +99,6 @@ public fun <T> Iterable<T>.asFlow(): Flow<T> = unsafeFlow {
100
99
/* *
101
100
* Creates a flow that produces values from the given iterable.
102
101
*/
103
- @ExperimentalCoroutinesApi
104
102
public fun <T > Iterator<T>.asFlow (): Flow <T > = unsafeFlow {
105
103
forEach { value ->
106
104
emit(value)
@@ -110,7 +108,6 @@ public fun <T> Iterator<T>.asFlow(): Flow<T> = unsafeFlow {
110
108
/* *
111
109
* Creates a flow that produces values from the given sequence.
112
110
*/
113
- @ExperimentalCoroutinesApi
114
111
public fun <T > Sequence<T>.asFlow (): Flow <T > = unsafeFlow {
115
112
forEach { value ->
116
113
emit(value)
@@ -120,7 +117,6 @@ public fun <T> Sequence<T>.asFlow(): Flow<T> = unsafeFlow {
120
117
/* *
121
118
* Creates a flow that produces values from the given array of elements.
122
119
*/
123
- @ExperimentalCoroutinesApi
124
120
public fun <T > flowOf (vararg elements : T ): Flow <T > = unsafeFlow {
125
121
for (element in elements) {
126
122
emit(element)
@@ -130,7 +126,6 @@ public fun <T> flowOf(vararg elements: T): Flow<T> = unsafeFlow {
130
126
/* *
131
127
* Creates flow that produces a given [value].
132
128
*/
133
- @ExperimentalCoroutinesApi
134
129
public fun <T > flowOf (value : T ): Flow <T > = unsafeFlow {
135
130
/*
136
131
* Implementation note: this is just an "optimized" overload of flowOf(vararg)
@@ -142,7 +137,6 @@ public fun <T> flowOf(value: T): Flow<T> = unsafeFlow {
142
137
/* *
143
138
* Returns an empty flow.
144
139
*/
145
- @ExperimentalCoroutinesApi
146
140
public fun <T > emptyFlow (): Flow <T > = EmptyFlow
147
141
148
142
private object EmptyFlow : Flow<Nothing> {
@@ -152,7 +146,6 @@ private object EmptyFlow : Flow<Nothing> {
152
146
/* *
153
147
* Creates a flow that produces values from the given array.
154
148
*/
155
- @ExperimentalCoroutinesApi
156
149
public fun <T > Array<T>.asFlow (): Flow <T > = unsafeFlow {
157
150
forEach { value ->
158
151
emit(value)
@@ -162,7 +155,6 @@ public fun <T> Array<T>.asFlow(): Flow<T> = unsafeFlow {
162
155
/* *
163
156
* Creates flow that produces values from the given array.
164
157
*/
165
- @ExperimentalCoroutinesApi
166
158
public fun IntArray.asFlow (): Flow <Int > = unsafeFlow {
167
159
forEach { value ->
168
160
emit(value)
@@ -172,7 +164,6 @@ public fun IntArray.asFlow(): Flow<Int> = unsafeFlow {
172
164
/* *
173
165
* Creates flow that produces values from the given array.
174
166
*/
175
- @ExperimentalCoroutinesApi
176
167
public fun LongArray.asFlow (): Flow <Long > = unsafeFlow {
177
168
forEach { value ->
178
169
emit(value)
@@ -182,7 +173,6 @@ public fun LongArray.asFlow(): Flow<Long> = unsafeFlow {
182
173
/* *
183
174
* Creates flow that produces values from the given range.
184
175
*/
185
- @ExperimentalCoroutinesApi
186
176
public fun IntRange.asFlow (): Flow <Int > = unsafeFlow {
187
177
forEach { value ->
188
178
emit(value)
@@ -192,7 +182,6 @@ public fun IntRange.asFlow(): Flow<Int> = unsafeFlow {
192
182
/* *
193
183
* Creates flow that produces values from the given range.
194
184
*/
195
- @ExperimentalCoroutinesApi
196
185
public fun LongRange.asFlow (): Flow <Long > = flow {
197
186
forEach { value ->
198
187
emit(value)
0 commit comments