effect
effect copied to clipboard
InArray filter for strings
🚀 Feature request
Current Behavior
With S.literal, you can create a schema that validates a string belongs to a set of strings known at compile-time. But sometimes, the strings to validate against are only known at run-time.
Desired Behavior
A String filter that checks the string belongs to an array of strings passed as parameter.
Suggested Solution
export const inArray = <C, B extends A, A extends string = B>(
a: ReadonlyArray<C>,
f: (s: string) => (c: C) => boolean
) =>
S.filter<B, A>((s) => pipe(a, RA.findFirst(f(s)), O.isSome), {
message: () => 'Not one of the allowed values'
});
Who does this impact? Who is this for?
Describe alternatives you've considered
Additional context
Your environment
| Software | Version(s) |
|---|---|
| @effect/schema | |
| TypeScript |
+1 I think this should be more general though, accepting an Equivalence instead of only working with string[].