export function ok(value) { return { _tag: 'ok', value }; } export function err(error) { return { _tag: 'error', error }; } /** * Checks whether a value is an `Ok`. * Handy with TypeScript guards */ export function isOk(result) { return result._tag === 'ok'; } /** * Checks whether a value is an `Err`. * Handy with TypeScript guards */ export function isErr(either) { return either._tag === 'error'; } /** * Convert a `Promise` into a `Promise>`, * therefore catching the errors and being able to handle them explicitly */ export async function safeAsync(promise) { try { const value = await promise; return ok(value); } catch (e) { return err(e); } } //# sourceMappingURL=Result.js.map