# option-type

> An Option type for Flow, inspired by Rust.

Latest version **0.2.0** (published 2018-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install option-type
pnpm add option-type
yarn add option-type
bun add option-type
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2018-04-30 |
| First published | 2017-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | David Graham |
| Maintainers | dgraham |
| Keywords | optional, option, some, none, maybe, result |

## Links

- npm: https://www.npmjs.com/package/option-type
- Repository: https://github.com/dgraham/option-type
- Homepage: https://github.com/dgraham/option-type#readme
- Issues: https://github.com/dgraham/option-type/issues
- npm.io page: https://npm.io/package/option-type

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads
- [@react-md/material-icons](https://npm.io/package/@react-md/material-icons.md) — 1.6K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2018-04-30
- 0.1.4 — 2017-09-05
- 0.1.3 — 2017-09-03
- 0.1.2 — 2017-09-02
- 0.1.1 — 2017-08-10
- 0.1.0 — 2017-08-09

## README

# Option type

An [Option][] type for [Flow][], inspired by [Rust][].

[Option]: https://en.wikipedia.org/wiki/Option_type
[Flow]: https://flow.org
[Rust]: https://doc.rust-lang.org/std/option/index.html

## Usage

```js
import {type Option, Some, None} from 'option-type';

function divide(numerator: number, denominator: number): Option<number> {
  if (denominator === 0) {
    return None;
  } else {
    return Some(numerator / denominator);
  }
}

const result = divide(2, 3);
const message = result.match({
  Some: x => `Result: ${x}`,
  None: () => 'Cannot divide by zero'
});
console.log(message);
```

## Result

A [`Result`][result] type is also included in this package because it's so
closely related to `Option`.

```js

import {type Result, Ok, Err} from 'option-type';

function parse(json: string): Result<Object, Error> {
  try {
    return Ok(JSON.parse(json));
  } catch (e) {
    return Err(e);
  }
}

const result = parse('{"name": "hubot"}');
const message = result.match({
  Ok: x => `Result: ${x.name}`,
  Err: e => `Failed to parse JSON text: ${e}`
});
console.log(message);
```

[result]: https://doc.rust-lang.org/std/result/enum.Result.html

## Development

```
npm install
npm test
```

## License

Distributed under the MIT license. See LICENSE for details.

---
_Source: https://npm.io/package/option-type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
