JSPM

  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q47912F
  • License MIT

Simply typesafe Result and Option monads in typescript and javascript.

Package Exports

  • simply-result
  • simply-result/dist/main.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simply-result) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Latest released version Minified and gzipped bundle size Type support Downloads from NPM MIT licensed

simply-result

Simply typesafe Result and Option monads in typescript and javascript. 1kb minified and gzipped. Branchless implementation, waisting no processing cycles on unnecessary operations.

import {
    Result, Ok, Err,
    Option, Some, None,
    map, mapErr,
} from 'simply-result';

const doSomeWork = (): Result<number, Error> => Ok(3);

const a = doSomeWork(); // Result<number, Error>
const b = mapErr(a, e => e.name); // Result<number, string>
const c = map(b, v => v === 0 ? None : Some(1 / v)); // Result<Option<number>, string>
const d = c.unwrapOr(Some(0)); // Option<number>
const e = map(d, v => String(v * 6)); // Option<string>

console.log(e.unwrap()); // "2"

Installation

NPM

npm i simply-result

import {
    Result, Ok, Err,
    Option, Some, None,
    map, mapErr, match,
    Try, Get, transpose,
} from 'simply-result';

Demo

See ./demo