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

Function encodeRecords

packages/effect/src/encoding/Csv.ts:857–880  ·  view source on GitHub ↗
(options: EncodeOptions | undefined)

Source from the content-addressed store, hash-verified

855}
856
857const encodeRecords = <A, IE, Done>(options: EncodeOptions | undefined): Channel.Channel<
858 Arr.NonEmptyReadonlyArray<string>,
859 IE,
860 Done,
861 Arr.NonEmptyReadonlyArray<A>,
862 IE,
863 Done
864> => {
865 const { header, writeRecord } = makeWriter(options)
866 return Channel.fromTransform((upstream, _scope) =>
867 Effect.sync(() => {
868 let pending = header
869 const pull: Pull.Pull<Arr.NonEmptyReadonlyArray<string>, IE, Done> = Effect.suspend(() => {
870 if (pending !== undefined) {
871 const text = pending
872 pending = undefined
873 return Effect.succeed(Arr.of(text))
874 }
875 return Effect.flatMap(upstream, (records) => Effect.sync(() => Arr.map(records, writeRecord)))
876 })
877 return pull
878 })
879 )
880}
881
882/**
883 * Creates a channel that writes CSV records as text, one string per record.

Callers 3

encodeStringFunction · 0.85
encodeFunction · 0.85
encodeSchemaRecordsFunction · 0.85

Calls 5

makeWriterFunction · 0.70
ofMethod · 0.65
syncMethod · 0.45
succeedMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected