Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-monadable

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-monadable

Simple TypeScript Monads

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

TS-Monadable

A simple set of Monadic structures and typings for TypeScript projects.

Install

npm install ts-monadable

API

Maybe

The Maybe structures can be used to define an optional value. This value may be something or nothing. By wrapping return values in this monad, it forces explicit handling of empty returns.

import * as Monads from 'ts-monadable';

// simple constructor for an example
const func = (name: string, flag: boolean): Monads.Maybe<string> => {
    return flag ? Monads.Some(name) : Monads.None();
}

// various monadic methods can then be invoked
func.is('some'); // type-guard
func.unwrap(); // safe-unwrapping (throws on `none` with no alternative)

Result

Similar to the Maybe structure, Result structures explicitly define an alternative value for an error. This allows adding failure meta-data to results.

import * as Monads from 'ts-monadable';

// simple constructor for an example
const func = (name: string): Monads.Result<string, string> => {
    return name === 'ts-monadable' ? Monads.Okay(name) : Monads.Error("Invalid name given!");
}

License

MIT

Keywords

FAQs

Package last updated on 04 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc