0.5.0 • Published 5 years ago

flow-algebra-rs v0.5.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

flow-algebra-rs CircleCI

Flow implementations of Rust Option<T> Result<T, E>.

Install

$ npm install --save flow-algebra-rs

API implementation status

Option

Result

Note: flow-algebra-rs APIs are provided as camelCase.

Usage

// @flow

import { Some, Ok } from 'flow-algebra-rs'

import type { Option, Result } from 'flow-algebra-rs'

const option: Option<number> = Some.new(10)

const result: Result<number, string> = Ok.new(10)

Utility

Null-safe and Exception-safe programming helper utilities are available.

Option

// @flow

import { Optional } from 'flow-algebra-rs'

const nullableVaule: ?number = null

const value = Optional.new(nullableValue)
  .map(n => n * 2)
  .unwrapOr(0)

console.log(`value is ${value}`) // value is 0

Result

// @flow

import { Try } from 'flow-algebra-rs'

const invalidJSON = 'to be error'

const value = Try.new((): {n: number} => JSON.parse(invalidJSON))
  .map(json => json.n * 2)
  .unwrapOr(0)

console.log(`value is ${value}`) // value is 0