MCPcopy Create free account
hub / github.com/Effect-TS/effect / writer

Function writer

packages/effect/src/internal/stream.ts:1378–1401  ·  view source on GitHub ↗
(
    last: Option.Option<A>
  )

Source from the content-addressed store, hash-verified

1376 <A, E, R>(self: Stream.Stream<A, E, R>, f: (x: A, y: A) => boolean) => Stream.Stream<A, E, R>
1377>(2, <A, E, R>(self: Stream.Stream<A, E, R>, f: (x: A, y: A) => boolean): Stream.Stream<A, E, R> => {
1378 const writer = (
1379 last: Option.Option<A>
1380 ): Channel.Channel<Chunk.Chunk<A>, Chunk.Chunk<A>, E, E, void, unknown> =>
1381 core.readWithCause({
1382 onInput: (input: Chunk.Chunk<A>) => {
1383 const [newLast, newChunk] = Chunk.reduce(
1384 input,
1385 [last, Chunk.empty<A>()] as const,
1386 ([option, outputs], output) => {
1387 if (Option.isSome(option) && f(option.value, output)) {
1388 return [Option.some(output), outputs] as const
1389 }
1390 return [Option.some(output), pipe(outputs, Chunk.append(output))] as const
1391 }
1392 )
1393 if (Chunk.isEmpty(newChunk)) return writer(newLast)
1394 return core.flatMap(
1395 core.write(newChunk),
1396 () => writer(newLast)
1397 )
1398 },
1399 onFailure: core.failCause,
1400 onDone: () => core.void
1401 })
1402 return new StreamImpl(pipe(toChannel(self), core.pipeTo(writer(Option.none()))))
1403})
1404

Callers 1

stream.tsFile · 0.85

Calls 6

pipeFunction · 0.70
isEmptyMethod · 0.65
writeMethod · 0.65
mapMethod · 0.65
pollMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected