Option that covers all API functions from Scala Option monad in javascript for handling null in declarative way
npm install --save scala-like-option
const optionFactory = require('scala-like-option')
var some = optionFactory.Some('some-content');
var transformation = optionFactory.map(content => 'other-content'); // == 'other-content'
var none = optionFactory.Option(null); // option from null == none
var none = optionFactory.None();
var some = optionFactory.Option('some-content'); // Some('some-content')
var some = some.getOrElse('other-content') // 'some-content'
var some = some.fold('empty', c => 'data') // returns 'data'
Returns the item or the elseObject if None
Arguments:
- elseObject: the object that returns of was None
Returns the element or throws NoSuchElementException if was None
Returns current option if Some or the Else if None
Arguments:
- Else: other option to return
Returns the element or null if was None
Return true if None and false if Some
Return false if None and true if Some
Returns different option with the transformer predicate
Arguments:
- transformer: function that gets the element and returns new object
Return value from supplied function, one for None and one For Some
Arguments:
- ifEmpty: value returned from this function if is None
- applyNonEmpty: value returned from this function if is Some
Returns different option for given transformer
Arguments:
- transformer: function that gets the element and returns new option, it may be None
Returns the content if predicate returns true
Arguments:
- predicate: function that gets the element and returns true/false
Returns the content if predicate returns false
Arguments:
- predicate: function that gets the element and returns true/false
Returns the content if predicate returns true
Arguments:
- predicate: function that gets the element and returns true/false
Returns true if give predicate on this element returns true, if None returns always true
Arguments:
- predicate: function that gets the element and returns true/false
Returns true if the element is equal to give parameter, if none returns false
Arguments:
- containElement: element to check equality
Checks if element exists for given predicate
Arguments:
- predicate: function that return true/false and gets the element
Execute function with element, do nothing when None
Arguments:
- executor: function that called with the element
Return array from option, if None it returns empty array
Returns iterator from option, end iterator if none