import z from "zod";

export type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };

export const zResult = <T, E>() =>
	z.discriminatedUnion("ok", [
		z.object({
			ok: z.literal(true),
			value: z.custom<T>(),
		}),
		z.object({
			ok: z.literal(false),
			error: z.custom<E>(),
		}),
	]);
