safe-func-safe-prom

1.1.1 • Public • Published

safe-func-safe-prom


This module quickly turned into tri-fp which is the active library for this functionality. You can:

import { tri as safe, triP as safeP } from "tri-fp";

...if you like the names in this module.


  • Make both functions and promises more functional by removing the need for try-catch.
  • Handle application errors and native exceptions differently.

Wrap a function in safe, or a promise in safeP, to transform all outcomes except native exceptions into an error-first pair. Don't use try-catch or .catch.

import { safe, safeP } from "safe-func-safe-prom";

// Sync
const [error, result] = safe(myFunction)(arg1, arg2);

// Async, direct promise
const [error, result] = await safeP(myPromise);

// Async, promise returning function
const [error, result] = await safeP(myPromiseReturningFunc)(arg1, arg2);

// Native errors/exceptions will still throw. Don't catch these; Find your bug.

Motivation

Inspired by / Thanks to

Package Sidebar

Install

npm i safe-func-safe-prom

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

4.56 kB

Total Files

4

Last publish

Collaborators

  • ez