INNER CODE UNIT · JavaScript
optional
gnh1201/welsonjs · app.js:56
var optional = function(f, defaultValue, finalizer, fallback, error) {
var result = defaultValue;
var currentError = null;
try {
if (typeof f !== "function") {
throw new Error("The first argument must be a function");
}
result = f(error);
} catch (e) {
currentError = e;
if (typeof fallback === "function") {
result = optional(fallback, defaultValue, null, null, currentError); // call fallback with the error
}
} finally {
if (typeof finalizer === "function") {
try {
finalizer(result, currentError);