Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/effect-app/src/Schema/ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ type ProvidedCodec<Self extends S.Top, R> = S.Codec<
Exclude<Self["EncodingServices"], R>
>

export const NonEmptyArrayAsTuple: typeof S.NonEmptyArray = S.NonEmptyArray
export type NonEmptyArrayAsTuple<ValueSchema extends S.Top> = S.NonEmptyArray<ValueSchema>

/**
* 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 extends S.Top>(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({
Expand Down
Loading