UNPKG

unenum

Version:

Universal ADT utilities for TypeScript.

15 lines (14 loc) 378 B
export function from(fn) { try { const value = fn(); if (value instanceof Promise) { return value .then((value) => ({ _type: "Ok", value })) .catch((error) => ({ _type: "Error", error })); } return { _type: "Ok", value }; } catch (error) { return { _type: "Error", error }; } }