Skip to content

Latest commit

History

History
50 lines (34 loc) 路 740 Bytes

README.md

File metadata and controls

50 lines (34 loc) 路 740 Bytes

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)