Hyperlinkv0.8.0-beta.28

ChannelSchema

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

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

When to use

Use to encode typed channel input into the schema's encoded representation before passing chunks to an encoded downstream boundary.

Details

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

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