view who was fronting when a record was made
1export type Result<T, E> =
2 | {
3 ok: true;
4 value: T;
5 }
6 | {
7 ok: false;
8 error: E;
9 };
10
11export const ok = <T, E>(value: T): Result<T, E> => {
12 return { ok: true, value };
13};
14export const err = <T, E>(error: E): Result<T, E> => {
15 return { ok: false, error };
16};
17export const expect = <T, E>(
18 v: Result<T, E>,
19 msg: string = "expected result to not be error:",
20) => {
21 if (v.ok) {
22 return v.value;
23 }
24 throw `${msg} ${v.error}`;
25};