effect-io-ai

Package: effect
Module: Channel

Channel.splitLines

Splits upstream string chunks into lines, recognizing \n, \r\n, and standalone \r as line terminators. The behavior matches String.linesIterator regardless of how the input is chunked.

Details

A line terminator at the very end of the stream does not produce a trailing empty line (consistent with String.linesIterator). Conversely, if the stream ends without a terminator the final partial line is still emitted.

Example (Splitting string chunks into lines)

import { Effect, Stream } from "effect"

Effect.runPromise(Effect.gen(function*() {
  const result = yield* Stream.runCollect(
    Stream.splitLines(Stream.make("hel", "lo\r\nwor", "ld\n"))
  )
  console.log(result)
  // [ 'hello', 'world' ]
}))

Signature

declare const splitLines: <Err, Done>() => Channel<Arr.NonEmptyReadonlyArray<string>, Err, Done, Arr.NonEmptyReadonlyArray<string>, Err, Done>

Source

Since v2.0.0