1.0.0 • Published 8 years ago
bs-option v1.0.0
bs-option
Some useful functions for dealing with Some and None.
Getting Started
Install bs-option using yarn:
yarn add bs-optionThen add bs-option to bs-dependencies in bsconfig.json.
Usage
let someValue = Some(42);
let fourtyTwo = Option.unwrap(someValue);API
Option.isSome(o)- returnstrueifoisSome(a)Option.isNone(o)- returnstrueifoisNoneOption.unwrap(o)- returnsainSome(a)or raisesOption.UnexpectedNoneOption.expect(o, message)- returnsainSome(a)or raisesOption.ExpectedSome(message)Option.map(o, f)- returnsSome(f(a))forSome(a), orNoneifoisNoneOption.unwrapOr(o, default)- same asunwrapbut returnsdefaultifoisNoneOption.unwrapOrElse(o, f)- same asunwrapbut returns the result of the application offifoisNoneOption.mapOr(o, default)- same asmapbut returnsSome(default)ifoisNoneOption.mapOrElse(o, f)- same asmapbut returnsSome(f())ifoisNone