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

@nehemy/result-monad

v1.0.2

Published

A simple project to help developers work with Result type

Downloads

2

Readme

Result

In functional programming, a Result Monad is a type that represents the result of a computation that can potentially fail or produce an error. It provides a way to handle errors or exceptional cases in a functional and composable manner.

The Result Monad typically has two possible values:

  • Success: Represents a successful computation or operation. It contains the result or value produced by the computation.

  • Failure: Represents a failed computation or operation. It contains information about the error or exceptional condition that occurred.

The key idea behind the Result Monad is to encapsulate the success or failure of a computation within the monadic type. By using this monadic structure, you can chain operations together and propagate the error state without explicit error handling in each step.

Build and Test

License

A simple Typescript utility library for functional programming with result monad.

Installation

You can install Library Name via NPM:

npm install @nehemy/result

Usage

To use Result, simply add a reference to the package in your typescript project and include the appropriate import:

import { Result } from "@nehemy/result";

Then, you can use the result class as follow and its methods:

let result = new Result<number>(12);
let failureResult = new Result<number>(new Error()); 

console.log(result.hasValue); // true
console.log(result.isSuccessful); // true
console.log(result.isNotSuccessful); // false
console.log(result.value); // 12

console.log(failureResult.hasValue); // false
console.log(failureResult.isSuccessful); // false
console.log(failureResult.isNotSuccessful); // true
// it is important to check if result is successful before getting result's value
console.log(failureResult.value); // throws error


result = new Result<number>(12);
failureResult = new Result<number>(new Error());

result.or(4);
console.log(result.value); // 12

failureResult.or(4);
console.log(failureResult.value); // 4

result.orInvoke(() => 4); // 12
failureResult.orInvoke(() => 4); //4 


result.match(
  value => console.log(value),
  error => console.log("Error")
); // 12

failureResult.match(
  value => console.log(value),
  error => console.log("Error")
); // "Error"

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for more information.

License

Library Name is licensed under the MIT License. See LICENSE for more information.