try-js
Type/construct for handling errors in Node.js, inspired by Scala's Try type.
Example usage #1, happy case:
var Try = ; var result = Try ; console; // Prints 20
Example usage #2, failure case:
var Try = ; var result = Try ; console; // Prints -1
API doc
Table of functions
of
Accepts a supplier function resulting in a failure or success Try.
var newTry = Try;
success
Static helper function for creating a success Try.
var successTry = Try;
failure
Static helper function for creating a failure Try.
var failureTry = Try;
filter
Function for filtering, where a predicate match results in a success try, and a failure.
var successTry = Try ;
var failureTry = Try ;
flatMap
Function for mapping on another Try, used to flatten a nested Try instances.
var successTry = Try ;
var failureTry = Try ;
getOrElse
Accepts a default value which is returned in case of failure, otherwise the value is returned.
var two = Try ;
isFailure
Returns whether the Try is a Failure or not.
var correct = Try ;
isSuccess
Returns whether the Try is a Success or not.
var correct = Try ;
onFailure
Function for performing an operation on the failure Try. Disregards the return value of the provided function.
var failureTry = Try ;
onSuccess
Function for performing an operation on the success Try. Disregards the return value of the provided function.
var successTry = Try ;
map
Accepts function that transforms a value if the current Try is a success Try.
var twentySuccessTry = Try ;
orElse
Accepts a function with a another try for Failure mapping.
var successTry = Try ;