npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@js-box/arithmetic-types

v1.0.1

Published

## Result

Downloads

3

Readme

Arithmetic Types

Result

export interface Result<T, E> {
  // Returns res if the result is Ok, otherwise returns the Err value of self.
  and<U>(res: Result<U, E>): Result<U, E>
  // Calls op if the result is Ok, otherwise returns the Err value of self.
  andThen<U>(op: (val: T) => Result<U, E>): Result<U, E>
  // Converts from Result<T, E> to Option<E>.
  err(): Option<E>
  // Returns true if the result is Err.
  isErr(): boolean
  // Returns true if the result is Ok.
  isOk(): boolean
  // Maps a Result<T, E> to Result<U, E> by applying a function to a contained Ok value, leaving an Err value untouched.
  map<U>(f: (val: T) => U): Result<U, E>;
  // Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err value, leaving an Ok value untouched.
  mapErr<U>(f: (err: E) => U): Result<T, U>;
  // Returns the provided default (if Err), or applies a function to the contained value (if Ok)
  mapOr<U>(def: U, f: (val: T) => U): U
  // Maps a Result<T, E> to U by applying fallback function default to a contained Err value, or function f to a contained Ok value.
  mapOrElse<U>(fallback: (err: E) => U, f: (val: T) => U): U,
  // Converts from Result<T, E> to Option<T>.
  ok(): Option<T>
  // Returns res if the result is Err, otherwise returns the Ok value of self.
  or(res: Result<T, E>): Result<T, E>
  // Calls op if the result is Err, otherwise returns the Ok value of self.
  orElse<F>(op: (err: E) => Result<T, F>): Result<T, F>
  // Returns the contained Ok value
  unwrap(): T
  // Returns the contained Ok value or a provided default.
  unwrapOr(val: T): T
  // Returns the contained Ok value or computes it from a closure.
  unwrapOrElse(f: (err: E) => T): T
}

export function Ok<T>(val: T): Result<T, never>

export function Err<E>(err: E): Result<never, E> 

Option

export interface Option<T> {
  // Returns None if the option is None, otherwise returns optb.
  and<U>(optb: Option<U>): Option<U>,
  // Returns None if the option is None, otherwise calls f with the wrapped value and returns the result.
  andThen<U>(f: (val: T) => Option<U>): Option<U>,
  // Returns true if the option is a None value.
  isNone(): boolean,
  // Returns true if the option is a Some value.
  isSome(): boolean,
  // Maps an Option<T> to Option<U> by applying a function to a contained value.
  map<U>(f: (val: T) => U): Option<U>,
  // Returns the provided default result (if none), or applies a function to the contained value (if any).
  mapOr<U>(def: U, f: (val: T) => U): U,
  // Computes a default function result (if none), or applies a different function to the contained value (if any).
  mapOrElse<U>(fallback: () => U, f: (val: T) => U): U,
  // Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err).
  okOr<E>(err: E): Result<T, E>,
  // Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err()).
  okOrElse<E>(err: () => E): Result<T, E>,
  // Returns the option if it contains a value, otherwise returns optb.
  or(optb: Option<T>): Option<T>,
  // Returns the option if it contains a value, otherwise calls f and returns the result.
  orElse(f: () => Option<T>): Option<T>,
  // Returns the contained Some value, consuming the self value.
  unwrap(): T,
  // Returns the contained Some value or a provided default.
  unwrapOr(def: T): T,
  // Returns the contained Some value or computes it from a closure.
  unwrapOrElse(f: () => T): T,
}

export function Some<T>(val: T): Option<T>

export function None(): Option<never>