A Promise like quasi monad but for Try.
npm install @microlib/try
bun add @microlib/try
import { Try } from "@microlib/try";
function task() {
if (Math.random() > 0.5) {
throw new Error("Something went wrong");
} else {
return "Hello";
}
}
const result = Try(task)
.catch(() => "Bye")
.then((v) => v + ", World!");
if (result.ok) {
console.log(result.value);
}
/*
Output can be any of these:
- Hello, World!
- Bye, World!
*/
Give a โญ๏ธ if this project helped you!