option-js

1.0.0 • Public • Published

OptionJS Build Status

This project is a Naive representation of Scala's Option[T]

Examples

const Option = require('option-js');
const DefaultValue = 50;
 
const value = Option.of(10);
const valueNull = Option.of(null);
 
console.log(value.getOrElse(DefaultValue)); // 10
console.log(valueNull.getOrElse(DefaultValue)); // 50
 
function user(name) {
    return {
        username: 'username', //Required
        name: Option.of(name)
    };
}
 
const withName = user("John");
const withoutName = user();
console.log(withName.name.getOrElse('Anonymous')); // John
console.log(withoutName.name.getOrElse('Anonymous')); // Anonymous

Readme

Keywords

none

Package Sidebar

Install

npm i option-js

Weekly Downloads

4

Version

1.0.0

License

ISC

Last publish

Collaborators

  • grillorafael