Class Option.Some<A>

  • All Implemented Interfaces:
    Effect.Applicant<A>, Maybe<A>, java.io.Serializable, java.lang.Iterable<A>
    Enclosing class:
    Option<A>

    static final class Option.Some<A>
    extends Option<A>
    One of the big two actual implementation classes.
    • Field Detail

      • value

        private final A value
    • Constructor Detail

      • Some

        private Some​(A value)
    • Method Detail

      • fold

        public <B> B fold​(java.util.function.Supplier<? extends B> none,
                          java.util.function.Function<? super A,​? extends B> f)
        Description copied from class: Option
        If this is a some value apply the some function, otherwise get the None value.
        Specified by:
        fold in class Option<A>
        Type Parameters:
        B - the result type
        Parameters:
        none - the supplier of the None type
        f - the function to apply if this is a Some
        Returns:
        the appropriate value
      • get

        public A get()
        Description copied from interface: Maybe
        Get the value if defined. Throw an exception otherwise.
        Returns:
        the wrapped value
      • isDefined

        public boolean isDefined()
        Description copied from interface: Maybe
        If the type contains a value return true.
        Returns:
        true if this holds a value, false otherwise.
      • getOrError

        public A getOrError​(java.util.function.Supplier<java.lang.String> err)
        Description copied from interface: Maybe
        Get the value or throws an error with the supplied message if not defined.

        Used when absolutely sure this is defined.

        Parameters:
        err - the message for the error.
        Returns:
        the contained value.
      • getOrThrow

        public <X extends java.lang.Throwable> A getOrThrow​(java.util.function.Supplier<X> ifUndefined)
                                                     throws X extends java.lang.Throwable
        Description copied from interface: Maybe
        Get the value or throws the supplied throwable if not defined.

        Used when absolutely sure this is defined.

        Type Parameters:
        X - exception type
        Parameters:
        ifUndefined - the supplier of the throwable.
        Returns:
        the contained value.
        Throws:
        X - the throwable the supplier creates if there is no value.
        X extends java.lang.Throwable
      • foreach

        @Deprecated
        public void foreach​(Effect<? super A> effect)
        Deprecated.
        Description copied from interface: Effect.Applicant
        Perform the given side-effect for each contained element.
        Parameters:
        effect - the input to use for performing the effect.
      • forEach

        public void forEach​(java.util.function.Consumer<? super A> effect)
      • toOptional

        public java.util.Optional<A> toOptional()
        Description copied from class: Option
        Create an Optional from this option. Will throw a NullPointerException if this option is defined and contains a null value.
        Specified by:
        toOptional in class Option<A>
        Returns:
        Optional.of(Object) with the value if defined and not null, Optional.empty() if not defined.
      • toStream

        public java.util.stream.Stream<A> toStream()
        Description copied from class: Option
        Create a Stream from this option.
        Specified by:
        toStream in class Option<A>
        Returns:
        Stream.of(Object) with the value if defined, Stream.empty() if not defined.
      • contains

        public boolean contains​(A elem)
        Description copied from interface: Maybe
        Tests whether the option contains a given value as an element.
        Parameters:
        elem - the element to test
        Returns:
        true if the option has an element that is equal to elem, false otherwise