0.1.0 • Published 11 months ago

fairlie-functional v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

fairlie-functional

npm Build status npm bundle size

npm type definitions node-current NPM

Experimental

A lightweight functional library in typescript that helps dealing with failures the rail way

A lightweight functional library in typescript that helps dealing with failures the rail way

Hero image for fairlie-functional

Highlights:

  • A take on Railway Oriented Programming (ROP) in typescript
  • Each function will always yield a failure or a success
  • You can easily combine multiple functions into a single unit using operators
  • Support for promises

A few examples of commands:

Bind two switch functions:

bindTwo(min3char, valueifyShort)('some text')

Bind three switch functions:

bindThree(min3char, max20char, valueifyShort)('some text')

Bind three similar switch functions:

bindSimilar([min3char, max20char, notDot])('some text')

Bypass a function if it fails:

bypass(addContextToError)(min3char('some text'))

Recovers a function if it fails:

recover(recoverToGood)(min3char('some text'))

Fallback to a different function if the first fail:

orFallback(min3char, fallbackToUppercase)('some text')

Convert a simple transformer to a switch function:

transformToSwitch((value: number) => value * 2)(17)

Documentation and links

Related

Installation

This package is ESM only.

yarn add fairlie-functional