import { inspect } from "util";
import { Result } from "..";

export function tryAssertOk<T, E>(r: Result<T, E>, a: (t: T) => void) {
  if (r.isOk()) {
    a(r.value);
  } else {
    throw `Result should have been Ok but was ${inspect(r, undefined, 15)}`;
  }
}

export function tryAssertErr<T, E>(r: Result<T, E>, a: (e: E) => void) {
  if (r.isErr()) {
    a(r.error);
  } else {
    throw `Result should have been Err but was ${inspect(r, undefined, 15)}`;
  }
}
