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

minimal-result

v1.0.3

Published

A minimal, Flow-typed, Rust-style Result library for functional exception handling.

Downloads

725

Readme

minimal-result

A minimal, Flow-typed, Rust-style Result library for functional exception handling.

Purpose

A result type is a disjoint union with two type variables. A result value contains either a data or error value.

type Result<Data, Error> =
    {| tag: 'Ok', +data: Data |}
  | {| tag: 'Err', +err: Error |}

A function should return a Result when errors are expected and recoverable.

Consider a parsing function that accepts a string and returns an abstract syntax tree ((s: string) => AST). If the string cannot be parsed - if it is malformed - the function should return an error indicating which line/character the error occurs on. If it can be parsed, it ought to return an AST. In other words, the function should have the type (s: string) => Result<AST,ParseError> where ParseError might resemble { explanation: string, line: number, character: number }.

For more on the Result types, see the Rust documentation and the r-result rationale section.

r-result is a similar javascript library. The publication of minimal-result was motivated by a desire for a library which:

  • Has simple flow types, and is published with them.
  • Offers a static function, rather than method-based API.

API

  • Ok

    • Purpose: Take a value of type Data, return an Ok Result with this value.
    • Type: <Data, Error>(data: Data) => Result<Data, Error>
  • Err

    • Purpose: Take a value of some type Error, return an Err Result with this value.
    • Type: <Data, Error>(err: Error) => Result<Data, Error>
  • andThen

    • Purpose: Given a Result and a function that returns a Result, apply the function to the value, unless the value is an Err, in which case simply return it unaltered. This can be chained together to provide "fall through" flow control.
    • Type: <Data, NewData, Error>(result: Result<Data, Error>, f: Data => Result<NewData, Error>) => Result<NewData, Error>
  • mapOk

    • Purpose: Apply a function to the Data value within a Result if it is Ok, wrap the result in an Ok. Err falls through.
    • Type: <Data, Error, NewData>(result: Result<Data, Error>, f: Data => NewData) => Result<NewData, Error>
  • mapErr

    • Type: <Data, NewError, Error>(result: Result<Data, Error>, f: Error => NewError) => Result<Data, NewError>
  • unwrapOrElse

    • Type: <Data, Error>(result: Result<Data, Error>, f: Error => Data) => Data
  • collectResultMap

    • Type: <MapVal, Data, Error>(oldMap: { [key: string]: MapVal }, f: (string, MapVal) => Result<Data, Error>) => Result<{ [key: string]: Data }, Error>
  • collectResultArray

    • Type: <ArrayVal, Data, Error>(oldArray: ArrayVal[], f: ArrayVal => Result<Data, Error>) => Result<Data[], Error>
  • collectResultArrayIndexed

    • Type: <ArrayVal, Data, Error>(oldArray: ArrayVal[], f: (index: number, val: ArrayVal) => Result<Data, Error>) : Result<Data[], Error>

License

MIT

Contributors

Joshua Yanovski, Björn Westergard, Lougenia Bailey.