Skip to content

🤿 Dead simple functional try ... catch implementation

License

Notifications You must be signed in to change notification settings

motherthestate/tcts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tcts 🤿

Dead simple, functional, curriable try ... catch implementation.

Install

npm i tcts

Usage

TC - Try catch

import { tc } from 'tcts'

const [error, value] = tc(() => {
  // errorable code
  return value
})

// use atc for an async try catch
atc(async () => ..)

TCF - Try catch fallback

import { tcf } from 'tcts'

const safeParseNum = tcf(0, parseNum)

// partial application to reuse
const tcNumber = tcf(0)
const tcAction = tcf({ error: true })
TCF helpers
// other helpers

import { tcNull, tcNullish, tcNumber, tcRetry } from 'tcts'

tcNull(fn) // tcf(null, fn)
tcNullish(fn) // tcf(undefined, fn)
tcNumber(fn) // tcf(0, fn)
tcRetry(fn) // tcf(fn, fn)

About

🤿 Dead simple functional try ... catch implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published