Comparing version 24.0.0 to 25.0.0
@@ -7,6 +7,13 @@ import { reverse } from "./array.js"; | ||
const errorBoundry = (f) => { | ||
const codeLocation = currentLocation(); | ||
const codeLocation = currentLocation(4); | ||
return ((...x) => { | ||
try { | ||
return f(...x); | ||
const result = f(...x); | ||
if (result instanceof Promise) { | ||
return result.catch((e) => { | ||
console.error(codeLocation); | ||
throw e; | ||
}); | ||
} | ||
return result; | ||
} | ||
@@ -13,0 +20,0 @@ catch (e) { |
import { currentLocation } from "./trace.js"; | ||
import { sideEffect } from "./composition.js"; | ||
export const sideLog = (x) => { | ||
console.log(currentLocation(), x); | ||
console.log(currentLocation(3), x); | ||
return x; | ||
}; | ||
export const sideLogAfter = (f) => { | ||
const codeLocation = currentLocation(); | ||
const codeLocation = currentLocation(3); | ||
return ((...xs) => { | ||
@@ -22,3 +22,3 @@ const output = f(...xs); | ||
export const sideLogBefore = (f) => { | ||
const codeLocation = currentLocation(); | ||
const codeLocation = currentLocation(3); | ||
return ((...xs) => { | ||
@@ -25,0 +25,0 @@ console.log(codeLocation, xs.length === 1 ? xs[0] : xs); |
@@ -10,2 +10,2 @@ const frameToString = ({ line, file, column }) => `${file}:${line}:${column}`; | ||
const parseStackTrace = (trace, picker) => parseStackLine(picker(trace.split("\n"))); | ||
export const currentLocation = () => frameToString(parseStackTrace(new Error().stack, (x) => x[3])); | ||
export const currentLocation = (depth) => frameToString(parseStackTrace(new Error().stack, (x) => x[depth])); |
@@ -6,3 +6,3 @@ { | ||
"name": "gamla", | ||
"version": "24.0.0", | ||
"version": "25.0.0", | ||
"description": "Functional programming with async and type safety", | ||
@@ -9,0 +9,0 @@ "license": "MIT", |
@@ -10,6 +10,13 @@ "use strict"; | ||
const errorBoundry = (f) => { | ||
const codeLocation = (0, trace_js_1.currentLocation)(); | ||
const codeLocation = (0, trace_js_1.currentLocation)(4); | ||
return ((...x) => { | ||
try { | ||
return f(...x); | ||
const result = f(...x); | ||
if (result instanceof Promise) { | ||
return result.catch((e) => { | ||
console.error(codeLocation); | ||
throw e; | ||
}); | ||
} | ||
return result; | ||
} | ||
@@ -16,0 +23,0 @@ catch (e) { |
@@ -7,3 +7,3 @@ "use strict"; | ||
const sideLog = (x) => { | ||
console.log((0, trace_js_1.currentLocation)(), x); | ||
console.log((0, trace_js_1.currentLocation)(3), x); | ||
return x; | ||
@@ -13,3 +13,3 @@ }; | ||
const sideLogAfter = (f) => { | ||
const codeLocation = (0, trace_js_1.currentLocation)(); | ||
const codeLocation = (0, trace_js_1.currentLocation)(3); | ||
return ((...xs) => { | ||
@@ -29,3 +29,3 @@ const output = f(...xs); | ||
const sideLogBefore = (f) => { | ||
const codeLocation = (0, trace_js_1.currentLocation)(); | ||
const codeLocation = (0, trace_js_1.currentLocation)(3); | ||
return ((...xs) => { | ||
@@ -32,0 +32,0 @@ console.log(codeLocation, xs.length === 1 ? xs[0] : xs); |
@@ -13,3 +13,3 @@ "use strict"; | ||
const parseStackTrace = (trace, picker) => parseStackLine(picker(trace.split("\n"))); | ||
const currentLocation = () => frameToString(parseStackTrace(new Error().stack, (x) => x[3])); | ||
const currentLocation = (depth) => frameToString(parseStackTrace(new Error().stack, (x) => x[depth])); | ||
exports.currentLocation = currentLocation; |
@@ -7,3 +7,3 @@ import { Func, ReturnTypeUnwrapped } from "./typing.js"; | ||
export declare const logWith: <T>(...x: any[]) => (x: T) => T; | ||
export declare const timeit: <F extends (..._: any[]) => any>(handler: (elapsed: number, args: Parameters<F>, result: ReturnTypeUnwrapped<F>) => void, f: F) => F; | ||
export declare const timeit: <F extends Func>(handler: (elapsed: number, args: Parameters<F>, result: ReturnTypeUnwrapped<F>) => void, f: F) => F; | ||
export declare const assert: <T>(condition: (_: T) => boolean, errorMessage: string) => (x: T) => T; |
@@ -1,1 +0,1 @@ | ||
export declare const currentLocation: () => string; | ||
export declare const currentLocation: (depth: number) => string; |
190335
1649