8000 GitHub - microlib-js/try at v2.0.3
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

microlib-js/try

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 @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!

About

📦 A Promise like quasi monad but for Try.

Topics

Resources

License

Stars

Watchers

Forks

0