(
leftover: Option.Option<Chunk.Chunk<A>>,
delimiterIndex: number
)
| 6401 | <A, E, R>(self: Stream.Stream<A, E, R>, delimiter: Chunk.Chunk<A>) => Stream.Stream<Chunk.Chunk<A>, E, R> |
| 6402 | >(2, <A, E, R>(self: Stream.Stream<A, E, R>, delimiter: Chunk.Chunk<A>): Stream.Stream<Chunk.Chunk<A>, E, R> => { |
| 6403 | const next = ( |
| 6404 | leftover: Option.Option<Chunk.Chunk<A>>, |
| 6405 | delimiterIndex: number |
| 6406 | ): Channel.Channel<Chunk.Chunk<Chunk.Chunk<A>>, Chunk.Chunk<A>, E, E, unknown, unknown, R> => |
| 6407 | core.readWithCause({ |
| 6408 | onInput: (inputChunk: Chunk.Chunk<A>) => { |
| 6409 | let buffer: Array<Chunk.Chunk<A>> | undefined |
| 6410 | const [carry, delimiterCursor] = pipe( |
| 6411 | inputChunk, |
| 6412 | Chunk.reduce( |
| 6413 | [pipe(leftover, Option.getOrElse(() => Chunk.empty<A>())), delimiterIndex] as const, |
| 6414 | ([carry, delimiterCursor], a) => { |
| 6415 | const concatenated = pipe(carry, Chunk.append(a)) |
| 6416 | if ( |
| 6417 | delimiterCursor < delimiter.length && |
| 6418 | Equal.equals(a, pipe(delimiter, Chunk.unsafeGet(delimiterCursor))) |
| 6419 | ) { |
| 6420 | if (delimiterCursor + 1 === delimiter.length) { |
| 6421 | if (buffer === undefined) { |
| 6422 | buffer = [] |
| 6423 | } |
| 6424 | buffer.push(pipe(concatenated, Chunk.take(concatenated.length - delimiter.length))) |
| 6425 | return [Chunk.empty<A>(), 0] as const |
| 6426 | } |
| 6427 | return [concatenated, delimiterCursor + 1] as const |
| 6428 | } |
| 6429 | return [concatenated, Equal.equals(a, pipe(delimiter, Chunk.unsafeGet(0))) ? 1 : 0] as const |
| 6430 | } |
| 6431 | ) |
| 6432 | ) |
| 6433 | const output = buffer === undefined ? Chunk.empty<Chunk.Chunk<A>>() : Chunk.unsafeFromArray(buffer) |
| 6434 | return core.flatMap( |
| 6435 | core.write(output), |
| 6436 | () => next(Chunk.isNonEmpty(carry) ? Option.some(carry) : Option.none(), delimiterCursor) |
| 6437 | ) |
| 6438 | }, |
| 6439 | onFailure: (cause) => |
| 6440 | Option.match(leftover, { |
| 6441 | onNone: () => core.failCause(cause), |
| 6442 | onSome: (chunk) => |
| 6443 | channel.zipRight( |
| 6444 | core.write(Chunk.of(chunk)), |
| 6445 | core.failCause(cause) |
| 6446 | ) |
| 6447 | }), |
| 6448 | onDone: (done) => |
| 6449 | Option.match(leftover, { |
| 6450 | onNone: () => core.succeed(done), |
| 6451 | onSome: (chunk) => channel.zipRight(core.write(Chunk.of(chunk)), core.succeed(done)) |
| 6452 | }) |
| 6453 | }) |
| 6454 | return new StreamImpl(pipe(toChannel(self), core.pipeTo(next(Option.none(), 0)))) |
| 6455 | }) |
| 6456 |
no test coverage detected