Class LeftProjection<L,​R>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<L>

    public class LeftProjection<L,​R>
    extends java.lang.Object
    implements java.lang.Iterable<L>, java.io.Serializable
    This is a left-biased wrapper for an instance of Either.
    Since:
    1.1
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Option<T> asOption()
      Returns the value of the Right/Left in Some side in case the projection matches the side, else None.
      boolean exists​(java.util.function.Predicate<L> predicate)
      Returns false if Right or returns the result of applying the predicate to the Left value.
      Option<Either<L,​R>> filter​(java.util.function.Predicate<L> predicate)
      Returns a Some wrapping the Either if it's a Left and the value of the Left matches the predicate, else None .
      <T> Either<T,​R> flatMap​(java.util.function.Function<L,​Left<T,​R>> function)
      If this projection contains a Left then a new Left is returned containing the value from the original Right mapped via the provided function, else the contained Either is returned as is.
      boolean forAll​(java.util.function.Predicate<L> predicate)
      Returns true if Right or returns the result of applying the predicate to the Left value.
      T get()
      Returns the value of the Right/Left side in case the projection matches the side, else throw NoSuchElementException.
      L getOrElse​(java.util.function.Supplier<L> supplier)
      Returns the value if this is a Left else the value provided by the supplier.
      java.util.Iterator<T> iterator()
      Returns the iterator of the Right/Left side in case the projection matches the side.
      <T> Either<T,​R> map​(java.util.function.Function<L,​T> function)
      If this projection contains a Left then a new Left is returned containing the value from the original Right mapped via the provided function, else the contained Either is returned as is.
      T orNull()
      Returns the value of this projection if it is of the correct type else null.
      java.util.stream.Stream<T> stream()
      Returns the stream of the Right/Left side in case the projection matches the side.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, iterator, spliterator
    • Method Detail

      • exists

        public boolean exists​(java.util.function.Predicate<L> predicate)
        Returns false if Right or returns the result of applying the predicate to the Left value.
        Parameters:
        predicate - The predicate to apply
        Returns:
        If this is a Left and the predicate matches the value
        Since:
        1.1
      • getOrElse

        public L getOrElse​(java.util.function.Supplier<L> supplier)
        Returns the value if this is a Left else the value provided by the supplier.
        Parameters:
        supplier - The supplier
        Returns:
        The value
        Since:
        1.1
      • filter

        public Option<Either<L,​R>> filter​(java.util.function.Predicate<L> predicate)
        Returns a Some wrapping the Either if it's a Left and the value of the Left matches the predicate, else None .
        Parameters:
        predicate - The predicate to apply
        Returns:
        The resulting Option of the filter operation
        Since:
        1.1
      • forAll

        public boolean forAll​(java.util.function.Predicate<L> predicate)
        Returns true if Right or returns the result of applying the predicate to the Left value.
        Parameters:
        predicate - The predicate to apply
        Returns:
        If it is a match
        Since:
        1.1
      • map

        public <T> Either<T,​R> map​(java.util.function.Function<L,​T> function)
        If this projection contains a Left then a new Left is returned containing the value from the original Right mapped via the provided function, else the contained Either is returned as is.
        Type Parameters:
        T - The type to return as the new Left
        Parameters:
        function - The function
        Returns:
        Mapped Either
        Since:
        1.1
      • flatMap

        public <T> Either<T,​R> flatMap​(java.util.function.Function<L,​Left<T,​R>> function)
        If this projection contains a Left then a new Left is returned containing the value from the original Right mapped via the provided function, else the contained Either is returned as is.
        Type Parameters:
        T - The type to return as the new Left
        Parameters:
        function - The function
        Returns:
        Mapped Either
        Since:
        1.2
      • asOption

        public Option<T> asOption()
        Returns the value of the Right/Left in Some side in case the projection matches the side, else None.
        That is:
        If this is a RightProjection with a Right
        or
        If this is a LeftProjection with a Left.
        Then then return Some containing the value of the Left/Right.
        Any other case, return None.
        Returns:
        The Option
        Since:
        1.1
      • get

        public T get()
        Returns the value of the Right/Left side in case the projection matches the side, else throw NoSuchElementException.
        That is:
        If this is a RightProjection with a Right
        or
        If this is a LeftProjection with a Left.
        Then return the value of the Left/Right.
        Any other case, throw NoSuchElementException.
        Returns:
        The value
        Since:
        1.1
      • iterator

        public java.util.Iterator<T> iterator()
        Returns the iterator of the Right/Left side in case the projection matches the side.
        That is:
        If this is a RightProjection with a Right
        or
        If this is a LeftProjection with a Left.
        Then return an iterator with the value for the Left/Right.
        Else return an empty iterator
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Returns:
        The iterator
        Since:
        1.1
      • stream

        public java.util.stream.Stream<T> stream()
        Returns the stream of the Right/Left side in case the projection matches the side.
        That is:
        If this is a RightProjection with a Right
        or
        If this is a LeftProjection with a Left.
        Then return a stream with the value for the Left/Right.
        Else return an empty stream
        Returns:
        The stream
        Since:
        1.1
      • orNull

        public T orNull()
        Returns the value of this projection if it is of the correct type else null.
        That is:
        If this is a RightProjection with a Right
        or
        If this is a LeftProjection with a Left.
        Then return the value of the Left/Right.
        Any other case, return null.
        In an essence this is a specialized version of getOrElse(Supplier) where the supplier returns null.
        getOrElse(() -> null)
        Returns:
        The value or null
        Since:
        1.1