Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

tryThunk

import { tryThunk } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/fn.ts";

Wrap a thunk (a Fn that takes no arguments) in a try catch block, using an onThrow function (that should itself never throw) to handle a default case should the original function throw. This is useful for wrapping functions that might throw.

@example
import * as F from "./fn.ts";

const getZero = (): number => {
  if (Math.random() > 0.5) {
    throw new Error("Too high!");
  }
  return 0;
}

const result = F.tryThunk(getZero, () => 0); // 0
function tryThunk<A>(ua: Fn<void, A>, onThrow: Fn<unknown, A>): A;
§
tryThunk<A>(ua: Fn<void, A>, onThrow: Fn<unknown, A>): A
[src]

§Type Parameters

§Parameters

§
ua: Fn<void, A>
[src]
§
onThrow: Fn<unknown, A>
[src]

§Return Type