export const example: schema.Schema<string, { a: "a"; b: string }> =
schema.transformResult(
pipe(schema.string, arrayFromDelimitedString(":")),
schema.struct({ a: schema.literal("a"), b: schema.string }),
(arr) => {
const myTuple = schema.tuple(
schema.literal("a"),
schema.string.pipe(schema.nonEmpty())
);
try {
return pipe(arr, schema.parseSync(myTuple), ([a, b]) =>
parseResult.success({ a, b })
);
} catch (_) {
return parseResult.failure(parseResult.type(myTuple.ast, arr));
}
},
({ a, b }) => parseResult.success([a, b])
);
export const example: schema.Schema<string, { a: "a"; b: string }> =
schema.transformResult(
pipe(schema.string, arrayFromDelimitedString(":")),
schema.struct({ a: schema.literal("a"), b: schema.string }),
(arr) => {
const myTuple = schema.tuple(
schema.literal("a"),
schema.string.pipe(schema.nonEmpty())
);
try {
return pipe(arr, schema.parseSync(myTuple), ([a, b]) =>
parseResult.success({ a, b })
);
} catch (_) {
return parseResult.failure(parseResult.type(myTuple.ast, arr));
}
},
({ a, b }) => parseResult.success([a, b])
);