Option type inspired by Rust. It represents an optional value, an Option
is either Some
concrete value or it is None
.
yarn add @pacote/option
import { None, Some, map } from '@pacote/option'
function divide(numerator: number, denominator: number): Option<number> {
return denominator === 0 : None ? Some(numerator / denominator)
}
map(n => n + 1, divide(4, 2)) // => Some(3)
map(n => n + 1, divide(4, 0)) // => None
MIT © Luís Rodrigues.