| 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 | |