diff --git a/packages/effect-app/src/Schema/ext.ts b/packages/effect-app/src/Schema/ext.ts index 76794bfc4..ecb46a553 100644 --- a/packages/effect-app/src/Schema/ext.ts +++ b/packages/effect-app/src/Schema/ext.ts @@ -15,6 +15,15 @@ type ProvidedCodec = S.Codec< Exclude > +export const NonEmptyArrayAsTuple: typeof S.NonEmptyArray = S.NonEmptyArray +export type NonEmptyArrayAsTuple = S.NonEmptyArray + +/** + * An array that is non empty. Non emptyness is confirmed on the container, not as the first element (unlike on tuples) + */ +export const NonEmptyArray = (valueSchema: ValueSchema) => + S.Array(valueSchema).pipe(S.check(S.isMinLength(1)), S.decodeTo(S.toType(S.NonEmptyArray(valueSchema)))) + // TODO: v4 migration - Date is no longer by default encoded to string. const DateString = S.String.annotate({