wellcrafted
Version:
Delightful TypeScript patterns for elegant, type-safe applications
33 lines (31 loc) • 1.32 kB
TypeScript
import { Result } from "./result-_socO0Ud.js";
//#region src/result/tap-err.d.ts
/**
* Result-flow combinator. Logs on the `Err` branch and returns the `Result`
* unchanged. Mirrors Rust's `Result::inspect_err` and Effect's
* `tapErrorCause`.
*
* Takes a log **method**, not a whole logger. The caller picks the level at
* the pipeline site — the same typed error can be logged as `warn` inside a
* retry loop and as `error` on the last attempt, without the variant itself
* carrying level. This is the `tracing::warn!(?err)` vs
* `tracing::error!(?err)` idiom translated to Result-flow.
*
* No message argument. The typed error owns its message; a message
* parameter here would drift away from the variant's template over time.
*
* @example
* const result = await tryAsync({
* try: () => writeTable(path),
* catch: (cause) => MarkdownError.TableWrite({ path, cause }),
* }).then(tapErr(log.warn));
*
* @example Level chosen at call site
* await tryAttempt().then(tapErr(log.warn)); // inside retry
* await tryFinal().then(tapErr(log.error)); // last try, giving up
*/
declare function tapErr<T, E>(logFn: (err: E) => void): (result: Result<T, E>) => Result<T, E>;
//# sourceMappingURL=tap-err.d.ts.map
//#endregion
export { tapErr };
//# sourceMappingURL=tap-err-C0xfVXtz.d.ts.map