Combining Schemas for Language Code Transformation

I have a schema that goes from something like en-US to en:

export const Iso639A1FromLanguage = Schema.transformOrFail(Schema.String, Schema.String, {
  strict: true,
  decode: (value) => Effect.succeed(value.split('-')[0]),
  encode: (input, _, ast) => ParseResult.fail(new ParseResult.Type(ast, input, 'Not possible')),
});


and then I have a schema which goes from "en" to "eng" (iso 639-1 to iso-639-3).

export const Iso639A3FromIso639A1 = Schema.transformOrFail(Schema.String, Schema.String, {
  strict: true,
  decode: (value) =>
    Effect.gen(function* () {
      const { iso639A1ToIso639A3 } = yield* Iso639LookupService;
      return yield* iso639A1ToIso639A3(value);
    }),
  encode: (value) =>
    Effect.gen(function* () {
      const { iso639A3ToIso639A1 } = yield* Iso639LookupService;
      return yield* iso639A3ToIso639A1(value);
    }),
});


If I want to define my response schema now to go from en-US to eng, how would I do that?

const mySchema = Schema.Struct({
  language: Iso639A1FromLanguage.pipe(Iso639A3FromIso639A1)
});


this does not seem to work as I expect it to work.
Was this page helpful?