flow-algebra-rs
v0.5.0
Published
Rust Option<T> and Result<T, E> types for Flow
Downloads
6
Readme
flow-algebra-rs 
Flow implementations of Rust Option<T> Result<T, E>.
Install
$ npm install --save flow-algebra-rsAPI implementation status
Option
- [x] is_some
- [x] is_none
- [x] unwrap
- [x] unwrap_or
- [x] unwrap_or_else
- [x] map
- [x] map_or
- [x] map_or_else
- [ ] ok_or
- [ ] ok_or_else
- [ ] and
- [x] and_then
- [ ] filter
- [x] or
- [x] or_else
- [ ] take
Result
- [x] is_ok
- [x] is_err
- [x] ok
- [ ] err
- [x] map
- [x] map_err
- [ ] and
- [x] and_then
- [x] or
- [x] or_else
- [x] unwrap_or
- [x] unwrap_or_else
- [x] unwrap
- [x] unwrap_err
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 0Result
// @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