Package org.eclipse.collections.api
Interface LazyIterable<T>
-
- All Superinterfaces:
InternalIterable<T>,Iterable<T>,RichIterable<T>
public interface LazyIterable<T> extends RichIterable<T>
A LazyIterable is RichIterable which will defer evaluation for certain methods like select, reject, collect, etc. Any methods that do not return a LazyIterable when called will cause evaluation to be forced.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description LazyIterable<RichIterable<T>>chunk(int size)Creates a deferred chunk iterable.<V> LazyIterable<V>collect(Function<? super T,? extends V> function)Creates a deferred iterable for collecting elements from the current iterable.LazyBooleanIterablecollectBoolean(BooleanFunction<? super T> booleanFunction)Returns a lazy BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction.LazyByteIterablecollectByte(ByteFunction<? super T> byteFunction)Returns a lazy ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction.LazyCharIterablecollectChar(CharFunction<? super T> charFunction)Returns a lazy CharIterable which will transform the underlying iterable data to char values based on the charFunction.LazyDoubleIterablecollectDouble(DoubleFunction<? super T> doubleFunction)Returns a lazy DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction.LazyFloatIterablecollectFloat(FloatFunction<? super T> floatFunction)Returns a lazy FloatIterable which will transform the underlying iterable data to float values based on the floatFunction.<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.LazyIntIterablecollectInt(IntFunction<? super T> intFunction)Returns a lazy IntIterable which will transform the underlying iterable data to int values based on the intFunction.LazyLongIterablecollectLong(LongFunction<? super T> longFunction)Returns a lazy LongIterable which will transform the underlying iterable data to long values based on the longFunction.LazyShortIterablecollectShort(ShortFunction<? super T> shortFunction)Returns a lazy ShortIterable which will transform the underlying iterable data to short values based on the shortFunction.<P,V>
LazyIterable<V>collectWith(Function2<? super T,? super P,? extends V> function, P parameter)Same asRichIterable.collect(Function)with aFunction2and specified parameter which is passed to the block.LazyIterable<T>concatenate(Iterable<T> iterable)Creates a deferred iterable that will join this iterable with the specified iterable.LazyIterable<T>distinct()Creates a deferred distinct iterable to get distinct elements from the current iterable.LazyIterable<T>drop(int count)Creates a deferred drop iterable for the current iterable using the specified count as the limit.LazyIterable<T>dropWhile(Predicate<? super T> predicate)<V> LazyIterable<V>flatCollect(Function<? super T,? extends Iterable<V>> function)Creates a deferred flattening iterable for the current iterable.default <P,V>
LazyIterable<V>flatCollectWith(Function2<? super T,? super P,? extends Iterable<V>> function, P parameter)TgetFirst()Returns the first element of an iterable.<R extends Collection<T>>
Rinto(R target)Iterates over this iterable adding all elements into the target collection.LazyIterable<T>reject(Predicate<? super T> predicate)Creates a deferred iterable for rejecting elements from the current iterable.<P> LazyIterable<T>rejectWith(Predicate2<? super T,? super P> predicate, P parameter)Similar toRichIterable.reject(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.LazyIterable<T>select(Predicate<? super T> predicate)Creates a deferred iterable for selecting elements from the current iterable.<S> LazyIterable<S>selectInstancesOf(Class<S> clazz)Returns all elements of the source collection that are instances of the Classclazz.<P> LazyIterable<T>selectWith(Predicate2<? super T,? super P> predicate, P parameter)Similar toRichIterable.select(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.LazyIterable<T>take(int count)Creates a deferred take iterable for the current iterable using the specified count as the limit.LazyIterable<T>takeWhile(Predicate<? super T> predicate)LazyIterable<T>tap(Procedure<? super T> procedure)Creates a deferred tap iterable.<S> LazyIterable<Pair<T,S>>zip(Iterable<S> that)Creates a deferred zip iterable.LazyIterable<Pair<T,Integer>>zipWithIndex()Creates a deferred zipWithIndex iterable.-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWith, forEachWithIndex
-
Methods inherited from interface java.lang.Iterable
iterator, spliterator
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, aggregateBy, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countBy, countByEach, countByEach, countByWith, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getLast, getOnly, groupBy, groupBy, groupByAndCollect, groupByEach, groupByEach, groupByUniqueKey, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, isEmpty, makeString, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, partition, partitionWith, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, size, sumByDouble, sumByFloat, sumByInt, sumByLong, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndex
-
-
-
-
Method Detail
-
getFirst
T getFirst()
Description copied from interface:RichIterableReturns 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:
getFirstin interfaceRichIterable<T>
-
select
LazyIterable<T> select(Predicate<? super T> predicate)
Creates a deferred iterable for selecting elements from the current iterable.- Specified by:
selectin interfaceRichIterable<T>
-
selectWith
<P> LazyIterable<T> selectWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableSimilar toRichIterable.select(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.E.g. return a
Collectionof Person elements where the person has an age greater than or equal to 18 yearsExample using a Java 8 lambda expression:
RichIterable<Person> selected = people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));- Specified by:
selectWithin interfaceRichIterable<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicate- See Also:
RichIterable.select(Predicate)
-
selectInstancesOf
<S> LazyIterable<S> selectInstancesOf(Class<S> clazz)
Description copied from interface:RichIterableReturns all elements of the source collection that are instances of the Classclazz.RichIterable<Integer> integers = List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);- Specified by:
selectInstancesOfin interfaceRichIterable<T>
-
reject
LazyIterable<T> reject(Predicate<? super T> predicate)
Creates a deferred iterable for rejecting elements from the current iterable.- Specified by:
rejectin interfaceRichIterable<T>- Parameters:
predicate- aPredicateto 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:RichIterableSimilar toRichIterable.reject(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.E.g. return a
Collectionof Person elements where the person has an age greater than or equal to 18 yearsExample using a Java 8 lambda expression:
RichIterable<Person> rejected = people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));- Specified by:
rejectWithin interfaceRichIterable<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicate- 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:
collectin interfaceRichIterable<T>
-
collectWith
<P,V> LazyIterable<V> collectWith(Function2<? super T,? super P,? extends V> function, P parameter)
Description copied from interface:RichIterableSame asRichIterable.collect(Function)with aFunction2and 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));- Specified by:
collectWithin interfaceRichIterable<T>- Parameters:
function- AFunction2to use as the collect transformation functionparameter- A parameter to pass in for evaluation of the second argumentPinfunction- Returns:
- A new
RichIterablethat contains the transformed elements returned byFunction2.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:
collectIfin interfaceRichIterable<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.
-
takeWhile
LazyIterable<T> takeWhile(Predicate<? super T> predicate)
- Since:
- 8.0
- See Also:
OrderedIterable.takeWhile(Predicate)
-
dropWhile
LazyIterable<T> dropWhile(Predicate<? super T> predicate)
- Since:
- 8.0
- See Also:
OrderedIterable.dropWhile(Predicate)
-
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 Iterable<V>> function)
Creates a deferred flattening iterable for the current iterable.- Specified by:
flatCollectin interfaceRichIterable<T>- Parameters:
function- TheFunctionto apply- Returns:
- a new flattened collection produced by applying the given
function
-
flatCollectWith
default <P,V> LazyIterable<V> flatCollectWith(Function2<? super T,? super P,? extends Iterable<V>> function, P parameter)
- Specified by:
flatCollectWithin interfaceRichIterable<T>- Since:
- 9.2
-
concatenate
LazyIterable<T> concatenate(Iterable<T> iterable)
Creates a deferred iterable that will join this iterable with the specified iterable.
-
zip
<S> LazyIterable<Pair<T,S>> zip(Iterable<S> that)
Creates a deferred zip iterable.- Specified by:
zipin interfaceRichIterable<T>- Type Parameters:
S- the type of the second half of the returned pairs- Parameters:
that- TheRichIterableproviding the second half of each result pair- Returns:
- A new
RichIterablecontaining pairs consisting of corresponding elements of thisRichIterableand that. The length of the returnedRichIterableis the minimum of the lengths of thisRichIterableand that.
-
zipWithIndex
LazyIterable<Pair<T,Integer>> zipWithIndex()
Creates a deferred zipWithIndex iterable.- Specified by:
zipWithIndexin interfaceRichIterable<T>- Returns:
- A new
RichIterablecontaining pairs consisting of all elements of thisRichIterablepaired 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:
chunkin interfaceRichIterable<T>- Parameters:
size- the number of elements per chunk- Returns:
- A
RichIterablecontainingRichIterables of sizesize, except the last will be truncated if the elements don't divide evenly.
-
tap
LazyIterable<T> tap(Procedure<? super T> procedure)
Creates a deferred tap iterable.- Specified by:
tapin interfaceRichIterable<T>- See Also:
RichIterable.each(Procedure),RichIterable.forEach(Procedure)
-
into
<R extends Collection<T>> R into(R target)
Iterates over this iterable adding all elements into the target collection.- Specified by:
intoin interfaceRichIterable<T>
-
collectBoolean
LazyBooleanIterable collectBoolean(BooleanFunction<? super T> booleanFunction)
Returns a lazy BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction.- Specified by:
collectBooleanin interfaceRichIterable<T>
-
collectByte
LazyByteIterable collectByte(ByteFunction<? super T> byteFunction)
Returns a lazy ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction.- Specified by:
collectBytein interfaceRichIterable<T>
-
collectChar
LazyCharIterable collectChar(CharFunction<? super T> charFunction)
Returns a lazy CharIterable which will transform the underlying iterable data to char values based on the charFunction.- Specified by:
collectCharin interfaceRichIterable<T>
-
collectDouble
LazyDoubleIterable collectDouble(DoubleFunction<? super T> doubleFunction)
Returns a lazy DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction.- Specified by:
collectDoublein interfaceRichIterable<T>
-
collectFloat
LazyFloatIterable collectFloat(FloatFunction<? super T> floatFunction)
Returns a lazy FloatIterable which will transform the underlying iterable data to float values based on the floatFunction.- Specified by:
collectFloatin interfaceRichIterable<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:
collectIntin interfaceRichIterable<T>
-
collectLong
LazyLongIterable collectLong(LongFunction<? super T> longFunction)
Returns a lazy LongIterable which will transform the underlying iterable data to long values based on the longFunction.- Specified by:
collectLongin interfaceRichIterable<T>
-
collectShort
LazyShortIterable collectShort(ShortFunction<? super T> shortFunction)
Returns a lazy ShortIterable which will transform the underlying iterable data to short values based on the shortFunction.- Specified by:
collectShortin interfaceRichIterable<T>
-
-