Interface LazyIterable<T>

    • Method Detail

      • getFirst

        T getFirst()
        Description copied from interface: RichIterable
        Returns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.

        The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.

        Specified by:
        getFirst in interface RichIterable<T>
      • selectWith

        <P> LazyIterable<T> selectWith​(Predicate2<? super T,​? super P> predicate,
                                       P parameter)
        Description copied from interface: RichIterable
        Similar to RichIterable.select(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

        E.g. return a Collection of Person elements where the person has an age greater than or equal to 18 years

        Example using a Java 8 lambda expression:

         RichIterable<Person> selected =
             people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));
         

        Example using an anonymous inner class:

         RichIterable<Person> selected =
             people.selectWith(new Predicate2<Person, Integer>()
             {
                 public boolean accept(Person person, Integer age)
                 {
                     return person.getAge()>= age;
                 }
             }, Integer.valueOf(18));
         
        Specified by:
        selectWith in interface RichIterable<T>
        Parameters:
        predicate - a Predicate2 to use as the select criteria
        parameter - a parameter to pass in for evaluation of the second argument P in predicate
        See Also:
        RichIterable.select(Predicate)
      • selectInstancesOf

        <S> LazyIterable<S> selectInstancesOf​(java.lang.Class<S> clazz)
        Description copied from interface: RichIterable
        Returns all elements of the source collection that are instances of the Class clazz.
         RichIterable<Integer> integers =
             List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
         
        Specified by:
        selectInstancesOf in interface RichIterable<T>
      • reject

        LazyIterable<T> reject​(Predicate<? super T> predicate)
        Creates a deferred iterable for rejecting elements from the current iterable.
        Specified by:
        reject in interface RichIterable<T>
        Parameters:
        predicate - a Predicate to use as the reject criteria
        Returns:
        a RichIterable that contains elements that cause Predicate.accept(Object) method to evaluate to false
      • rejectWith

        <P> LazyIterable<T> rejectWith​(Predicate2<? super T,​? super P> predicate,
                                       P parameter)
        Description copied from interface: RichIterable
        Similar to RichIterable.reject(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

        E.g. return a Collection of Person elements where the person has an age greater than or equal to 18 years

        Example using a Java 8 lambda expression:

         RichIterable<Person> rejected =
             people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));
         

        Example using an anonymous inner class:

         MutableList<Person> rejected =
             people.rejectWith(new Predicate2<Person, Integer>()
             {
                 public boolean accept(Person person, Integer age)
                 {
                     return person.getAge() < age;
                 }
             }, Integer.valueOf(18));
         
        Specified by:
        rejectWith in interface RichIterable<T>
        Parameters:
        predicate - a Predicate2 to use as the select criteria
        parameter - a parameter to pass in for evaluation of the second argument P in predicate
        See Also:
        RichIterable.select(Predicate)
      • collect

        <V> LazyIterable<V> collect​(Function<? super T,​? extends V> function)
        Creates a deferred iterable for collecting elements from the current iterable.
        Specified by:
        collect in interface RichIterable<T>
      • collectWith

        <P,​V> LazyIterable<V> collectWith​(Function2<? super T,​? super P,​? extends V> function,
                                                P parameter)
        Description copied from interface: RichIterable
        Same as RichIterable.collect(Function) with a Function2 and specified parameter which is passed to the block.

        Example using a Java 8 lambda expression:

         RichIterable<Integer> integers =
             Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1));
         

        Example using an anonymous inner class:

         Function2<Integer, Integer, Integer> addParameterFunction =
             new Function2<Integer, Integer, Integer>()
             {
                 public Integer value(Integer each, Integer parameter)
                 {
                     return each + parameter;
                 }
             };
         RichIterable<Integer> integers =
             Lists.mutable.with(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1));
         
        Specified by:
        collectWith in interface RichIterable<T>
        Parameters:
        function - A Function2 to use as the collect transformation function
        parameter - A parameter to pass in for evaluation of the second argument P in function
        Returns:
        A new RichIterable that contains the transformed elements returned by Function2.value(Object, Object)
        See Also:
        RichIterable.collect(Function)
      • collectIf

        <V> LazyIterable<V> collectIf​(Predicate<? super T> predicate,
                                      Function<? super T,​? extends V> function)
        Creates a deferred iterable for selecting and collecting elements from the current iterable.
        Specified by:
        collectIf in interface RichIterable<T>
      • take

        LazyIterable<T> take​(int count)
        Creates a deferred take iterable for the current iterable using the specified count as the limit.
      • drop

        LazyIterable<T> drop​(int count)
        Creates a deferred drop iterable for the current iterable using the specified count as the limit.
      • distinct

        LazyIterable<T> distinct()
        Creates a deferred distinct iterable to get distinct elements from the current iterable.
        Since:
        5.0
      • flatCollect

        <V> LazyIterable<V> flatCollect​(Function<? super T,​? extends java.lang.Iterable<V>> function)
        Creates a deferred flattening iterable for the current iterable.
        Specified by:
        flatCollect in interface RichIterable<T>
        Parameters:
        function - The Function to apply
        Returns:
        a new flattened collection produced by applying the given function
      • concatenate

        LazyIterable<T> concatenate​(java.lang.Iterable<T> iterable)
        Creates a deferred iterable that will join this iterable with the specified iterable.
      • zip

        <S> LazyIterable<Pair<T,​S>> zip​(java.lang.Iterable<S> that)
        Creates a deferred zip iterable.
        Specified by:
        zip in interface RichIterable<T>
        Type Parameters:
        S - the type of the second half of the returned pairs
        Parameters:
        that - The RichIterable providing the second half of each result pair
        Returns:
        A new RichIterable containing pairs consisting of corresponding elements of this RichIterable and that. The length of the returned RichIterable is the minimum of the lengths of this RichIterable and that.
      • zipWithIndex

        LazyIterable<Pair<T,​java.lang.Integer>> zipWithIndex()
        Creates a deferred zipWithIndex iterable.
        Specified by:
        zipWithIndex in interface RichIterable<T>
        Returns:
        A new RichIterable containing pairs consisting of all elements of this RichIterable paired with their index. Indices start at 0.
        See Also:
        RichIterable.zip(Iterable)
      • chunk

        LazyIterable<RichIterable<T>> chunk​(int size)
        Creates a deferred chunk iterable.
        Specified by:
        chunk in interface RichIterable<T>
        Parameters:
        size - the number of elements per chunk
        Returns:
        A RichIterable containing RichIterables of size size, except the last will be truncated if the elements don't divide evenly.
      • into

        <R extends java.util.Collection<T>> R into​(R target)
        Iterates over this iterable adding all elements into the target collection.
        Specified by:
        into in interface RichIterable<T>
      • collectInt

        LazyIntIterable collectInt​(IntFunction<? super T> intFunction)
        Returns a lazy IntIterable which will transform the underlying iterable data to int values based on the intFunction.
        Specified by:
        collectInt in interface RichIterable<T>