Hyperlinkv0.8.0-beta.28

ChannelSchema

ChannelSchema.decodeconsteffect/ChannelSchema.ts:98
<S extends Schema.Constraint>(schema: S): <
  IE = never,
  Done = unknown
>() => Channel.Channel<
  Arr.NonEmptyReadonlyArray<S["Type"]>,
  IE | Schema.SchemaError,
  Done,
  Arr.NonEmptyReadonlyArray<S["Encoded"]>,
  IE,
  Done,
  S["DecodingServices"]
>

Creates a channel that decodes non-empty chunks from the schema's encoded representation into schema values.

When to use

Use to validate and decode encoded channel output into typed schema values before application code consumes it.

Details

Decoding failures are emitted as SchemaError, and any decoding services required by the schema become channel requirements.

export const decode = <S extends Schema.Constraint>(
  schema: S
) =>
<IE = never, Done = unknown>(): Channel.Channel<
  Arr.NonEmptyReadonlyArray<S["Type"]>,
  IE | Schema.SchemaError,
  Done,
  Arr.NonEmptyReadonlyArray<S["Encoded"]>,
  IE,
  Done,
  S["DecodingServices"]
> => {
  const decode = Schema.decodeEffect(Schema.NonEmptyArray(schema))
  return Channel.fromTransform((upstream, _scope) => Effect.succeed(Effect.flatMap(upstream, (chunk) => decode(chunk))))
}
Referenced by 2 symbols