Interface Maybe<T>


public sealed interface Maybe<T>
Defines the contract for Maybe.
  • Method Details

    • none

      static <X> Maybe<X> none()
      Performs none.
      Returns:
      the result of none
    • of

      static <X> Maybe<X> of(X value)
      Creates an instance from the provided value.
      Parameters:
      value - the value value
      Returns:
      the result of of
    • some

      static <X> Maybe<X> some(X value)
      Performs some.
      Parameters:
      value - the value value
      Returns:
      the result of some
    • from

      static <X> Maybe<X> from(Optional<X> optional)
      Creates an instance from the provided source.
      Parameters:
      optional - the optional value
      Returns:
      the result of from
    • enumerable

      Enumerable<T> enumerable()
    • get

      T get()
    • isPresent

      boolean isPresent()
      Checks whether is Present.
      Returns:
      the result of isPresent
    • isAbsent

      boolean isAbsent()
      Checks whether is Absent.
      Returns:
      the result of isAbsent
    • ofType

      <R> Maybe<R> ofType(Class<R> type)
      Transforms the value T to type R. If the value is not of type T return none()
      Type Parameters:
      R -
      Parameters:
      type -
      Returns:
    • filter

      Maybe<T> filter(Predicate<T> predicate)
    • map

      <R> Maybe<R> map(Function<T,R> transform)
    • flatMap

      <R> Maybe<R> flatMap(Function<T,Maybe<R>> transform)
    • orNull

      T orNull()
    • orElseThrow

      T orElseThrow()
    • orElseThrow

      <E extends Throwable> T orElseThrow(Supplier<E> supplier) throws E
      Throws:
      E
    • orElse

      T orElse(T defaultValue)
    • orElseGet

      T orElseGet(Supplier<T> supplier)
    • or

      Maybe<T> or(Maybe<T> alternative)
    • orGet

      Maybe<T> orGet(Supplier<Maybe<T>> alternative)
    • zip

      <R, S> Maybe<R> zip(Maybe<S> other, BiFunction<T,S,R> calculation)
    • flatZip

      <R, S> Maybe<R> flatZip(Maybe<S> other, BiFunction<T,S,Maybe<R>> calculation)
    • merge

      Maybe<T> merge(Maybe<T> other, BiFunction<T,T,T> calculation)
    • flatMerge

      Maybe<T> flatMerge(Maybe<T> other, BiFunction<T,T,Maybe<T>> calculation)
    • toOptional

      Optional<T> toOptional()
      Performs ifPresent.
    • ifPresent

      void ifPresent(Consumer<T> consumer)
      Performs ifPresent.
      Parameters:
      consumer - the consumer value
    • ifPresentOrElse

      void ifPresentOrElse(Consumer<T> consumer, Runnable action)
      Performs ifPresentOrElse.
      Parameters:
      consumer - the consumer value
      action - the action value