optionalj
v0.1.0
Published
A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.
Downloads
2
Readme
Optional
How use:
Optional.ofNullable(null).get() // null
Optional.of(null).get(); // throw error about null value
Optional.ofNullable('foo').map(value => value + 'bar').get(); // foobar
Optional.ofNullable(null).map(value => value + 'bar').get(); // null
Optional.ofNullable(['foo', 'bar']).map(value => value + 'bar').get(); // ['foobar', 'barbar']
Optional.ofNullable(20).filter(value => value > 15).get(); // 20
Optional.ofNullable(20)
.filter(value => value > 25)
.orElse(value => value + 10).get(); // 30
Optional.ofNullable(20)
.filter(value => value > 25)
.orElseThrow(Error('Invalid value')); // throw error
Optional.ofNullable([20, 14]).filter(value => value > 15).get(); // [20]