Optional
Simple Java8-inspired monadic class to represent optional values
Installation
npm install --save data-optional
Usage
; ;; empty.isPresent; // falsevalue.isPresent; // true
You can also convert nullable types into optionals.
; ;; empty.isPresent; // falsevalue.isPresent; // true
There are also a number of computations that can be done functionally with this module.
; value = Optional.ofNullable 1 ; value = value.map n * 3 ; // Optional.of( 3 ) value = value.flatMap n % 2 === 0 ? Optional.of n : Optional.empty ; // Optional.empty() value.orElse 0 ; // 0