2.0.4 • Published 9 months ago

@microlib/try v2.0.4

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

📦 @microlib/try

npm version npm downloads Github Actions Bundlephobia

A Promise like quasi monad but for Try.

🚀 Installation

npm install @microlib/try
bun add @microlib/try

📖 Usage

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!")
  .unwrap();

console.log(result);

/* 

Output can be any of these:
- Hello, World!
- Bye, World!

*/

🍀 Show your Support

Give a ⭐️ if this project helped you!

2.0.3

9 months ago

2.0.2

9 months ago

2.0.4

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.0

9 months ago