( self: Channel<ReadonlyArray<OutElem>, OutErr, OutDone, InElem, InErr, InDone, Env> )
| 3237 | * @since 4.0.0 |
| 3238 | */ |
| 3239 | export const flattenArray = < |
| 3240 | OutElem, |
| 3241 | OutErr, |
| 3242 | OutDone, |
| 3243 | InElem, |
| 3244 | InErr, |
| 3245 | InDone, |
| 3246 | Env |
| 3247 | >( |
| 3248 | self: Channel<ReadonlyArray<OutElem>, OutErr, OutDone, InElem, InErr, InDone, Env> |
| 3249 | ): Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env> => |
| 3250 | transformPull(self, (pull) => { |
| 3251 | let array: ReadonlyArray<OutElem> | undefined |
| 3252 | let index = 0 |
| 3253 | const pump = Effect.suspend(function loop(): Pull.Pull<OutElem, OutErr, OutDone> { |
| 3254 | if (array === undefined) { |
| 3255 | return Effect.flatMap(pull, (array_) => { |
| 3256 | switch (array_.length) { |
| 3257 | case 0: |
| 3258 | return loop() |
| 3259 | case 1: |
| 3260 | return Effect.succeed(array_[0]) |
| 3261 | default: { |
| 3262 | array = array_ |
| 3263 | return Effect.succeed(array_[index++]) |
| 3264 | } |
| 3265 | } |
| 3266 | }) |
| 3267 | } |
| 3268 | const next = array[index++] |
| 3269 | if (index >= array.length) { |
| 3270 | array = undefined |
| 3271 | index = 0 |
| 3272 | } |
| 3273 | return Effect.succeed(next) |
| 3274 | }) |
| 3275 | return Effect.succeed(pump) |
| 3276 | }) |
| 3277 | |
| 3278 | /** |
| 3279 | * Flattens a channel that emits `Take` values into a channel that emits the |
nothing calls this directly
no test coverage detected