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

Function encodeString

packages/effect/src/encoding/JsonArray.ts:751–787  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

749 * @since 4.0.6
750 */
751export const encodeString = <IE = never, Done = unknown>(): Channel.Channel<
752 Arr.NonEmptyReadonlyArray<string>,
753 IE | JsonArrayError,
754 Done,
755 Arr.NonEmptyReadonlyArray<unknown>,
756 IE,
757 Done
758> =>
759 Channel.fromTransform((upstream, _scope) =>
760 Effect.sync(() => {
761 let started = false
762 let done: Pull.Pull<never, never, Done> | undefined
763 type Out = Pull.Pull<Arr.NonEmptyReadonlyArray<string>, IE | JsonArrayError, Done>
764 const pull: Out = Effect.suspend((): Out => {
765 if (done !== undefined) return done
766 return Pull.matchEffect(upstream, {
767 onSuccess: (values): Out => {
768 let text: string
769 try {
770 text = (started ? "," : "[") + values.map(stringify).join(",")
771 } catch (error) {
772 if (isJsonArrayError(error)) return Effect.fail(error)
773 throw error
774 }
775 started = true
776 return Effect.succeed(Arr.of(text))
777 },
778 onFailure: Effect.failCause,
779 onDone: (value) => {
780 done = Cause.done(value)
781 return Effect.succeed(Arr.of(started ? "]" : "[]"))
782 }
783 })
784 })
785 return pull
786 })
787 )
788
789/**
790 * Creates a channel that writes a stream of values as UTF-8 bytes of one JSON

Callers 2

encodeFunction · 0.70
encodeSchemaStringFunction · 0.70

Calls 8

isJsonArrayErrorFunction · 0.85
failMethod · 0.65
ofMethod · 0.65
syncMethod · 0.45
joinMethod · 0.45
mapMethod · 0.45
succeedMethod · 0.45
doneMethod · 0.45

Tested by

no test coverage detected