safety-net v0.0.1
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=>anchorhandrail=>safety-netguideRail=>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 -Sor
npm i safety-net -SAPI
safetyNet
Parameters
assertionfunction a function to test the input withwrongPathfunction a function to prepare data before it passes into the Left pathrightPathfunction a function to modify after it passes into the Right pathinputany any input
Returns (GuidedLeft | GuidedRight) a Future
anchor
Add safety to your pipelines!
Parameters
assertionfunction boolean-returning functionwrongPathfunction function invoked if the inputs are badinputany any input
Returns (GuidedRight | GuidedLeft) Left / Right -wrapped value
tether
tie multiple assertions some input
Parameters
anchorsArray<functions> an array of assertion, failCase pairsgoodPathfunction what to do if things go wellinputany whatever
Returns (GuidedLeft | GuidedRight) a Future
bimap
Parameters
rejectionMapfunction do something if function receives a rejectionresolutionMapfunction do something if function receives a resolutionfutureFuture a Future(value)
Returns Future a mapped future
8 years ago