Implementing Validation Without Effect.gen in TypeScript

Can this be written without the Effect.gen? I know that i could do new ValidationError(..) immediately, but then I can't do the valibot check

const makeValidationService = () => {
    const validateSchema = <TInput, TOutput, TIssue extends v.BaseIssue<unknown>>(
        schema: v.BaseSchema<TInput, TOutput, TIssue>,
        data: unknown,
        config?: v.Config<TIssue>
    ) => {
        return Effect.try({
            try: () => v.parse(schema, data, config),
            catch: (error) =>
                Effect.gen(function* () {
                    if (v.isValiError(error)) {
                        yield* new ValidationError({
                            message: error.message,
                            issues: error.issues
                        });
                    }
                    yield* Effect.die(error);
                })
        }).pipe(Effect.withSpan("ValidationService.validateSchema"));
    };

    return {
        validateSchema
    };
};
Was this page helpful?