Comparing version 57.0.0 to 58.0.0
@@ -9,1 +9,5 @@ import { Func, ReturnTypeUnwrapped } from "./typing.js"; | ||
export declare const coerce: <T>(x: T | null | undefined) => T; | ||
type AugmentReturnType<F extends Func, T> = (...inputs: Parameters<F>) => ReturnType<F> | T; | ||
export declare const tryCatch: <F extends Func, T>(f: F, fallback: (e: Error, ...xs: Parameters<F>) => T) => AugmentReturnType<F, T>; | ||
export declare const catchWithNull: <F extends Func>(f: F) => (...aruments: Parameters<F>) => ReturnType<F> | null; | ||
export {}; |
@@ -76,1 +76,15 @@ import { currentLocation } from "./trace.js"; | ||
}; | ||
export const tryCatch = (f, fallback) => ((...x) => { | ||
try { | ||
const result = f(...x); | ||
return result instanceof Promise | ||
? result.catch((e) => { | ||
return fallback(e, ...x); | ||
}) | ||
: result; | ||
} | ||
catch (e) { | ||
return fallback(e, ...x); | ||
} | ||
}); | ||
export const catchWithNull = (f) => tryCatch(f, () => null); |
{ | ||
"name": "gamla", | ||
"version": "57.0.0", | ||
"version": "58.0.0", | ||
"description": "Functional programming with async and type safety", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -9,1 +9,5 @@ import { Func, ReturnTypeUnwrapped } from "./typing.js"; | ||
export declare const coerce: <T>(x: T | null | undefined) => T; | ||
type AugmentReturnType<F extends Func, T> = (...inputs: Parameters<F>) => ReturnType<F> | T; | ||
export declare const tryCatch: <F extends Func, T>(f: F, fallback: (e: Error, ...xs: Parameters<F>) => T) => AugmentReturnType<F, T>; | ||
export declare const catchWithNull: <F extends Func>(f: F) => (...aruments: Parameters<F>) => ReturnType<F> | null; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.coerce = exports.assert = exports.timeit = exports.logBefore = exports.logAfter = exports.logAround = exports.sideLog = void 0; | ||
exports.catchWithNull = exports.tryCatch = exports.coerce = exports.assert = exports.timeit = exports.logBefore = exports.logAfter = exports.logAround = exports.sideLog = void 0; | ||
const trace_js_1 = require("./trace.js"); | ||
@@ -86,1 +86,17 @@ const juxt_js_1 = require("./juxt.js"); | ||
exports.coerce = coerce; | ||
const tryCatch = (f, fallback) => ((...x) => { | ||
try { | ||
const result = f(...x); | ||
return result instanceof Promise | ||
? result.catch((e) => { | ||
return fallback(e, ...x); | ||
}) | ||
: result; | ||
} | ||
catch (e) { | ||
return fallback(e, ...x); | ||
} | ||
}); | ||
exports.tryCatch = tryCatch; | ||
const catchWithNull = (f) => (0, exports.tryCatch)(f, () => null); | ||
exports.catchWithNull = catchWithNull; |
226723
2270