import { Result, ok, err } from './result'; export function attempt(fn: () => T): Result { try { return ok(fn()); } catch (e) { return err(e as E); } } export function attemptAsync( fn: () => Promise, ): Promise> { return fn() .then((value) => ok(value)) .catch((error) => err(error as E)); }