1.0.5 • Published 7 years ago

@t0bst4r/optional v1.0.5

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
7 years ago

@t0bst4r/optional

pipeline status coverage report

Add java-like optional functionality to your application.

Installation and Usage

Installation via npm

npm install @t0bst4r/optional

Usage

Import the package to your project files:

import { Optional } from "@t0bst4r/optional";

Create an optional

To create a new optional use Optional.Of(yourValue) or Optional.OfNullable(yourValue). You could also create an empty optional with Optional.Empty().

Methods

  • map your optional to an other typed value
  • check if the optional isPresent()
  • get() the value of the optional - throws an exception if the optional is not present
  • if the optional is Empty
    • get a fallback value with orElse(fallbackValue)
    • get a fallback value using a supplier with orElseGet(fallbackSupplier)
    • get another optional with or(anotherFallbackOptional)
    • get another optional using a supplier with orGet(fallbackSupplier)
  • execute a piece of code if the optional is present with ifPresent(callback)
1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago