option-t

Installation
npm install --save option-t
Usage
var OptionType = require('option-t').OptionType;
var some = new OptionType(1);
console.log(some.isSome);
console.log(some.value);
console.log(some.unwrap());
var none = new OptionType();
console.log(none.isSome);
console.log(some.value);
console.log(none.unwrap());
JSON Representation
Some<T>
new OptionType(1)
will be:
{
"is_some": true,
"value": 1
}
None
new OptionType()
will be:
{
"is_some": false
}
API
see inlined JSDoc.
Semantics
This library represents Option type in ECMAScript.
So this object will be the one of following states:
Some<T>
: option.isSome === true
.None
: option.isSome === false
.
Some<T>
This type represents that there are some values T
.
If this value wraps null
, it just means that there is a null value.
None
(None<T>
)
This type represents that there is no value explicitly.
It is just None !== null
.
License
MIT License