Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/eitherway/lib/core/mod.ts>panic

Yet Another Option and Result Implementation - providing safe abstractions for fallible flows inspired by F# and Rust
Latest
function panic
import { panic } from "https://deno.land/x/eitherway@0.10.0/lib/core/mod.ts";

Use this to either throw <E> directly or wrap it in a Panic<E> if <E> is not a subtype of the native Error type

This can be useful in situations where:

  • the encountered error is truly unrecoverable
  • error handling is unfeasible
  • this behaviour is required per some contract (e.g. middlewares)
  • you want to emulate the behavior of .unwrap() from other libraries or languages

Examples

Example 1

import { Result, Option } from "https://deno.land/x/eitherway/mod.ts";
import { panic } from "./mod.ts"

function parseHex(hex: string): Result<number, TypeError> {
  const candidate = Number.parseInt(hex, 16);
  return Option.fromCoercible(candidate).okOrElse(() => TypeError());
}

const res = Result("0x10f2c").andThen(parseHex);

const value: number = res.unwrapOrElse(panic);

Parameters

optional
err: E

Returns

never