bs-option
Some useful functions for dealing with Some
and None
.
Getting Started
Install bs-option
using yarn:
yarn add bs-option
Then add bs-option
to bs-dependencies
in bsconfig.json
.
Usage
let someValue = Some(42);
let fourtyTwo = Option.unwrap(someValue);
API
-
Option.isSome(o)
- returnstrue
ifo
isSome(a)
-
Option.isNone(o)
- returnstrue
ifo
isNone
-
Option.unwrap(o)
- returnsa
inSome(a)
or raisesOption.UnexpectedNone
-
Option.expect(o, message)
- returnsa
inSome(a)
or raisesOption.ExpectedSome(message)
-
Option.map(o, f)
- returnsSome(f(a))
forSome(a)
, orNone
ifo
isNone
-
Option.unwrapOr(o, default)
- same asunwrap
but returnsdefault
ifo
isNone
-
Option.unwrapOrElse(o, f)
- same asunwrap
but returns the result of the application off
ifo
isNone
-
Option.mapOr(o, default)
- same asmap
but returnsSome(default)
ifo
isNone
-
Option.mapOrElse(o, f)
- same asmap
but returnsSome(f())
ifo
isNone