roption
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

roption

Build Status

Typescript Rust-like Option and Result types, with some small adjustments

Install

$ npm install --save roption

Usage

import { Option, Some, None } from 'roption';
 
function divide(numerator: number, denominator: number): Option<number> {
  if (denominator === 0) {
    return None();
  }
 
  return Some(numerator / denominator);
}
 
const result = divide(2, 3);
 
result.match(
  result => console.log('Result', result),
  () => console.log('Cannot divide by 0'),
);

See Rust Option and Rust Result documentation.

All functions have been converted in camelCase

/roption/

    Package Sidebar

    Install

    npm i roption

    Weekly Downloads

    32

    Version

    1.1.0

    License

    ISC

    Unpacked Size

    21.1 kB

    Total Files

    14

    Last publish

    Collaborators

    • dadounne