All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gs.collections.api.LazyIterable Maven / Gradle / Ivy

/*
 * Copyright 2015 Goldman Sachs.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gs.collections.api;

import java.util.Collection;

import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.function.primitive.BooleanFunction;
import com.gs.collections.api.block.function.primitive.ByteFunction;
import com.gs.collections.api.block.function.primitive.CharFunction;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.function.primitive.ShortFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.tuple.Pair;

/**
 * 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
 */
public interface LazyIterable
        extends RichIterable
{
    /**
     * @inheritDoc
     */
    T getFirst();

    /**
     * Creates a deferred iterable for selecting elements from the current iterable.
     */
    LazyIterable select(Predicate predicate);

    

LazyIterable selectWith(Predicate2 predicate, P parameter); LazyIterable selectInstancesOf(Class clazz); /** * Creates a deferred iterable for rejecting elements from the current iterable. */ LazyIterable reject(Predicate predicate);

LazyIterable rejectWith(Predicate2 predicate, P parameter); /** * Creates a deferred iterable for collecting elements from the current iterable. */ LazyIterable collect(Function function); LazyIterable collectWith(Function2 function, P parameter); /** * Creates a deferred iterable for selecting and collecting elements from the current iterable. */ LazyIterable collectIf(Predicate predicate, Function function); /** * Creates a deferred take iterable for the current iterable using the specified count as the limit. */ LazyIterable take(int count); /** * Creates a deferred drop iterable for the current iterable using the specified count as the limit. */ LazyIterable drop(int count); /** * Creates a deferred distinct iterable to get distinct elements from the current iterable. * * @since 5.0 */ LazyIterable distinct(); /** * Creates a deferred flattening iterable for the current iterable. */ LazyIterable flatCollect(Function> function); /** * Creates a deferred iterable that will join this iterable with the specified iterable. */ LazyIterable concatenate(Iterable iterable); /** * Creates a deferred zip iterable. */ LazyIterable> zip(Iterable that); /** * Creates a deferred zipWithIndex iterable. */ LazyIterable> zipWithIndex(); /** * Creates a deferred chunking iterable. */ LazyIterable> chunk(int size); /** * Creates a deferred tap iterable. */ LazyIterable tap(Procedure procedure); /** * Iterates over this iterable adding all elements into the target collection. */ > R into(R target); /** * Returns a lazy BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction. */ LazyBooleanIterable collectBoolean(BooleanFunction booleanFunction); /** * Returns a lazy ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction. */ LazyByteIterable collectByte(ByteFunction byteFunction); /** * Returns a lazy CharIterable which will transform the underlying iterable data to char values based on the charFunction. */ LazyCharIterable collectChar(CharFunction charFunction); /** * Returns a lazy DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction. */ LazyDoubleIterable collectDouble(DoubleFunction doubleFunction); /** * Returns a lazy FloatIterable which will transform the underlying iterable data to float values based on the floatFunction. */ LazyFloatIterable collectFloat(FloatFunction floatFunction); /** * Returns a lazy IntIterable which will transform the underlying iterable data to int values based on the intFunction. */ LazyIntIterable collectInt(IntFunction intFunction); /** * Returns a lazy LongIterable which will transform the underlying iterable data to long values based on the longFunction. */ LazyLongIterable collectLong(LongFunction longFunction); /** * Returns a lazy ShortIterable which will transform the underlying iterable data to short values based on the shortFunction. */ LazyShortIterable collectShort(ShortFunction shortFunction); }