Flow implementations of Rust Option<T>
Result<T, E>
.
$ npm install --save flow-algebra-rs
- is_some
- is_none
- unwrap
- unwrap_or
- unwrap_or_else
- map
- map_or
- map_or_else
- ok_or
- ok_or_else
- and
- and_then
- filter
- or
- or_else
- take
Note: flow-algebra-rs APIs are provided as camelCase
.
// @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)
Null-safe and Exception-safe programming helper utilities are available.
// @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
// @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