safety-net
a toolset for adding safety to your asynchronous functional pipelines
This module attempts to offer the same general API as handrail
(for dealing with synchronous logical disjunctions / Eithers) but to model asynchronous operations (using the excellent fluture library) instead.
Here's the mapping of APIs:
handrail
=> safety-net
rail
=>anchor
handrail
=>safety-net
guideRail
=>tether
Given the asynchronous goals of this library, multiRail
doesn't make as much sense, as chaining over the resulting values is problematic (when you can instead just add a clause to the tether
API)
multiRail
=> null
Install
yarn add safety-net -S
or
npm i safety-net -S
API
safetyNet
Parameters
assertion
function a function to test the input withwrongPath
function a function to prepare data before it passes into the Left pathrightPath
function a function to modify after it passes into the Right pathinput
any any input
Returns (GuidedLeft | GuidedRight) a Future
anchor
Add safety to your pipelines!
Parameters
assertion
function boolean-returning functionwrongPath
function function invoked if the inputs are badinput
any any input
Returns (GuidedRight | GuidedLeft) Left / Right -wrapped value
tether
tie multiple assertions some input
Parameters
anchors
Array<functions> an array of [assertion, failCase] pairsgoodPath
function what to do if things go wellinput
any whatever
Returns (GuidedLeft | GuidedRight) a Future
bimap
Parameters
rejectionMap
function do something if function receives a rejectionresolutionMap
function do something if function receives a resolutionfuture
Future a Future(value)
Returns Future a mapped future