MCPcopy Index your code
hub / github.com/Effect-TS/effect / collectAllWhileEffectReader

Function collectAllWhileEffectReader

packages/effect/src/internal/sink.ts:237–255  ·  view source on GitHub ↗
(
  predicate: (input: In) => Effect.Effect<boolean, E, R>,
  done: Chunk.Chunk<In>
)

Source from the content-addressed store, hash-verified

235
236/** @internal */
237const collectAllWhileEffectReader = <In, R, E>(
238 predicate: (input: In) => Effect.Effect<boolean, E, R>,
239 done: Chunk.Chunk<In>
240): Channel.Channel<Chunk.Chunk<In>, Chunk.Chunk<In>, E, never, Chunk.Chunk<In>, unknown, R> =>
241 core.readWith({
242 onInput: (input: Chunk.Chunk<In>) =>
243 pipe(
244 core.fromEffect(pipe(input, Effect.takeWhile(predicate), Effect.map(Chunk.unsafeFromArray))),
245 core.flatMap((collected) => {
246 const leftovers = pipe(input, Chunk.drop(collected.length))
247 if (Chunk.isEmpty(leftovers)) {
248 return collectAllWhileEffectReader(predicate, pipe(done, Chunk.appendAll(collected)))
249 }
250 return pipe(core.write(leftovers), channel.zipRight(core.succeed(pipe(done, Chunk.appendAll(collected)))))
251 })
252 ),
253 onFailure: core.fail,
254 onDone: () => core.succeed(done)
255 })
256
257/** @internal */
258export const collectAllWhileWith: {

Callers 1

collectAllWhileEffectFunction · 0.85

Calls 5

fromEffectMethod · 0.80
pipeFunction · 0.70
mapMethod · 0.65
isEmptyMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected