CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-collections--eclipse-collections-api

A comprehensive collections framework API for Java providing interfaces for object collections, primitive collections and lazy iterables

Pending
Overview
Eval results
Files

functional-interfaces.mddocs/

Functional Interfaces

Eclipse Collections provides rich functional programming support through comprehensive Function, Predicate, and Procedure interfaces. These interfaces extend Java's standard functional interfaces while adding Eclipse Collections-specific functionality and primitive specializations for all 8 primitive types.

Core Functional Interfaces

Functions

Functions transform input values to output values, providing the foundation for map/collect operations.

Function<T,V>

Single argument transformation function extending Java's Function interface.

package org.eclipse.collections.api.block.function;

@FunctionalInterface
public interface Function<T, V> extends java.util.function.Function<T, V> {
    // Primary transformation method
    V valueOf(T argument);
    
    // Java 8 compatibility (delegates to valueOf)
    @Override
    default V apply(T argument) {
        return this.valueOf(argument);
    }
}

Multi-Argument Functions

Functions for multiple input parameters.

// Zero argument function
package org.eclipse.collections.api.block.function;

@FunctionalInterface
public interface Function0<R> extends java.util.function.Supplier<R> {
    R value();
    
    @Override
    default R get() {
        return this.value();
    }
}

// Two argument function
@FunctionalInterface
public interface Function2<T1, T2, R> extends java.util.function.BiFunction<T1, T2, R> {
    R value(T1 argument1, T2 argument2);
    
    @Override
    default R apply(T1 argument1, T2 argument2) {
        return this.value(argument1, argument2);
    }
}

// Three argument function
@FunctionalInterface
public interface Function3<T1, T2, T3, R> {
    R value(T1 argument1, T2 argument2, T3 argument3);
}

Predicates

Predicates test boolean conditions, providing the foundation for filter/select/reject operations.

Predicate<T>

Single argument boolean test function extending Java's Predicate interface.

package org.eclipse.collections.api.block.predicate;

@FunctionalInterface
public interface Predicate<T> extends java.util.function.Predicate<T> {
    // Primary testing method
    boolean accept(T argument);
    
    // Java 8 compatibility (delegates to accept)
    @Override
    default boolean test(T argument) {
        return this.accept(argument);
    }
}

Multi-Argument Predicates

Predicates for multiple input parameters.

// Two argument predicate
package org.eclipse.collections.api.block.predicate;

@FunctionalInterface
public interface Predicate2<T, P> extends java.util.function.BiPredicate<T, P> {
    boolean accept(T argument1, P argument2);
    
    @Override
    default boolean test(T argument1, P argument2) {
        return this.accept(argument1, argument2);
    }
}

Procedures

Procedures perform side-effect operations without returning values, used in forEach operations.

Procedure<T>

Single argument side-effect operation.

package org.eclipse.collections.api.block.procedure;

@FunctionalInterface
public interface Procedure<T> extends java.util.function.Consumer<T> {
    // Primary side-effect method
    void value(T argument);
    
    // Java 8 compatibility (delegates to value)
    @Override
    default void accept(T argument) {
        this.value(argument);
    }
}

Multi-Argument Procedures

Procedures for multiple input parameters.

// Two argument procedure
package org.eclipse.collections.api.block.procedure;

@FunctionalInterface
public interface Procedure2<T, P> extends java.util.function.BiConsumer<T, P> {
    void value(T argument1, P argument2);
    
    @Override
    default void accept(T argument1, P argument2) {
        this.value(argument1, argument2);
    }
}

// Zero argument procedure (Runnable equivalent)
@FunctionalInterface
public interface Procedure0 extends Runnable {
    void value();
    
    @Override
    default void run() {
        this.value();
    }
}

Primitive Functional Interfaces

Eclipse Collections provides primitive specializations of all functional interfaces for each of the 8 primitive types, avoiding boxing overhead.

Primitive Functions

Object-to-Primitive Functions

Functions that transform objects to primitive values.

// Transform objects to int values
package org.eclipse.collections.api.block.function.primitive;

@FunctionalInterface
public interface IntFunction<T> extends java.util.function.ToIntFunction<T> {
    int intValueOf(T argument);
    
    @Override
    default int applyAsInt(T value) {
        return this.intValueOf(value);
    }
}

// Similar interfaces for all primitive types:
@FunctionalInterface
public interface BooleanFunction<T> {
    boolean booleanValueOf(T argument);
}

@FunctionalInterface
public interface ByteFunction<T> {
    byte byteValueOf(T argument);
}

@FunctionalInterface
public interface CharFunction<T> {
    char charValueOf(T argument);
}

@FunctionalInterface
public interface DoubleFunction<T> extends java.util.function.ToDoubleFunction<T> {
    double doubleValueOf(T argument);
    
    @Override
    default double applyAsDouble(T value) {
        return this.doubleValueOf(value);
    }
}

@FunctionalInterface
public interface FloatFunction<T> {
    float floatValueOf(T argument);
}

@FunctionalInterface
public interface LongFunction<T> extends java.util.function.ToLongFunction<T> {
    long longValueOf(T argument);
    
    @Override
    default long applyAsLong(T value) {
        return this.longValueOf(value);
    }
}

@FunctionalInterface
public interface ShortFunction<T> {
    short shortValueOf(T argument);
}

Primitive-to-Object Functions

Functions that transform primitive values to objects.

// Transform int values to objects
package org.eclipse.collections.api.block.function.primitive;

@FunctionalInterface
public interface IntToObjectFunction<V> extends java.util.function.IntFunction<V> {
    V valueOf(int argument);
    
    @Override
    default V apply(int value) {
        return this.valueOf(value);
    }
}

// Similar interfaces for all primitive types:
@FunctionalInterface
public interface BooleanToObjectFunction<V> {
    V valueOf(boolean argument);
}

@FunctionalInterface
public interface ByteToObjectFunction<V> {
    V valueOf(byte argument);
}

@FunctionalInterface
public interface CharToObjectFunction<V> {
    V valueOf(char argument);
}

@FunctionalInterface
public interface DoubleToObjectFunction<V> extends java.util.function.DoubleFunction<V> {
    V valueOf(double argument);
    
    @Override
    default V apply(double value) {
        return this.valueOf(value);
    }
}

@FunctionalInterface
public interface FloatToObjectFunction<V> {
    V valueOf(float argument);
}

@FunctionalInterface
public interface LongToObjectFunction<V> extends java.util.function.LongFunction<V> {
    V valueOf(long argument);
    
    @Override
    default V apply(long value) {
        return this.valueOf(value);
    }
}

@FunctionalInterface
public interface ShortToObjectFunction<V> {
    V valueOf(short argument);
}

Primitive-to-Primitive Functions

Functions that transform between primitive types.

// Transform int to int
package org.eclipse.collections.api.block.function.primitive;

@FunctionalInterface
public interface IntToIntFunction extends java.util.function.IntUnaryOperator {
    int valueOf(int argument);
    
    @Override
    default int applyAsInt(int operand) {
        return this.valueOf(operand);
    }
}

// Cross-type transformations
@FunctionalInterface
public interface IntToLongFunction extends java.util.function.IntToLongFunction {
    long valueOf(int argument);
    
    @Override
    default long applyAsLong(int value) {
        return this.valueOf(value);
    }
}

@FunctionalInterface
public interface IntToDoubleFunction extends java.util.function.IntToDoubleFunction {
    double valueOf(int argument);
    
    @Override
    default double applyAsDouble(int value) {
        return this.valueOf(value);
    }
}

@FunctionalInterface
public interface IntToFloatFunction {
    float valueOf(int argument);
}

@FunctionalInterface
public interface IntToCharFunction {
    char valueOf(int argument);
}

@FunctionalInterface
public interface IntToByteFunction {
    byte valueOf(int argument);
}

@FunctionalInterface
public interface IntToShortFunction {
    short valueOf(int argument);
}

@FunctionalInterface
public interface IntToBooleanFunction {
    boolean valueOf(int argument);
}

Primitive Predicates

Primitive Predicates

Boolean tests on primitive values.

// Test int values
package org.eclipse.collections.api.block.predicate.primitive;

@FunctionalInterface
public interface IntPredicate extends java.util.function.IntPredicate {
    boolean accept(int value);
    
    @Override
    default boolean test(int value) {
        return this.accept(value);
    }
}

// Similar interfaces for all primitive types:
@FunctionalInterface
public interface BooleanPredicate {
    boolean accept(boolean value);
}

@FunctionalInterface
public interface BytePredicate {
    boolean accept(byte value);
}

@FunctionalInterface
public interface CharPredicate {
    boolean accept(char value);
}

@FunctionalInterface
public interface DoublePredicate extends java.util.function.DoublePredicate {
    boolean accept(double value);
    
    @Override
    default boolean test(double value) {
        return this.accept(value);
    }
}

@FunctionalInterface
public interface FloatPredicate {
    boolean accept(float value);
}

@FunctionalInterface
public interface LongPredicate extends java.util.function.LongPredicate {
    boolean accept(long value);
    
    @Override
    default boolean test(long value) {
        return this.accept(value);
    }
}

@FunctionalInterface
public interface ShortPredicate {
    boolean accept(short value);
}

Object-Primitive Predicates

Boolean tests on object-primitive pairs.

// Test object-int pairs
package org.eclipse.collections.api.block.predicate.primitive;

@FunctionalInterface
public interface ObjectIntPredicate<T> {
    boolean accept(T object, int intParameter);
}

// Similar interfaces for all primitive types:
@FunctionalInterface
public interface ObjectBooleanPredicate<T> {
    boolean accept(T object, boolean booleanParameter);
}

@FunctionalInterface
public interface ObjectBytePredicate<T> {
    boolean accept(T object, byte byteParameter);
}

@FunctionalInterface
public interface ObjectCharPredicate<T> {
    boolean accept(T object, char charParameter);
}

@FunctionalInterface
public interface ObjectDoublePredicate<T> {
    boolean accept(T object, double doubleParameter);
}

@FunctionalInterface
public interface ObjectFloatPredicate<T> {
    boolean accept(T object, float floatParameter);
}

@FunctionalInterface
public interface ObjectLongPredicate<T> {
    boolean accept(T object, long longParameter);
}

@FunctionalInterface
public interface ObjectShortPredicate<T> {
    boolean accept(T object, short shortParameter);
}

Primitive Procedures

Primitive Procedures

Side-effect operations on primitive values.

// Side effects on int values
package org.eclipse.collections.api.block.procedure.primitive;

@FunctionalInterface
public interface IntProcedure extends java.util.function.IntConsumer {
    void value(int argument);
    
    @Override
    default void accept(int value) {
        this.value(value);
    }
}

// Similar interfaces for all primitive types:
@FunctionalInterface
public interface BooleanProcedure {
    void value(boolean argument);
}

@FunctionalInterface
public interface ByteProcedure {
    void value(byte argument);
}

@FunctionalInterface
public interface CharProcedure {
    void value(char argument);
}

@FunctionalInterface
public interface DoubleProcedure extends java.util.function.DoubleConsumer {
    void value(double argument);
    
    @Override
    default void accept(double value) {
        this.value(value);
    }
}

@FunctionalInterface
public interface FloatProcedure {
    void value(float argument);
}

@FunctionalInterface
public interface LongProcedure extends java.util.function.LongConsumer {
    void value(long argument);
    
    @Override
    default void accept(long value) {
        this.value(value);
    }
}

@FunctionalInterface
public interface ShortProcedure {
    void value(short argument);
}

Object-Primitive Procedures

Side-effect operations on object-primitive pairs.

// Side effects on object-int pairs
package org.eclipse.collections.api.block.procedure.primitive;

@FunctionalInterface
public interface ObjectIntProcedure<T> {
    void value(T object, int intParameter);
}

// Similar interfaces for all primitive types:
@FunctionalInterface
public interface ObjectBooleanProcedure<T> {
    void value(T object, boolean booleanParameter);
}

@FunctionalInterface
public interface ObjectByteProcedure<T> {
    void value(T object, byte byteParameter);
}

@FunctionalInterface
public interface ObjectCharProcedure<T> {
    void value(T object, char charParameter);
}

@FunctionalInterface
public interface ObjectDoubleProcedure<T> {
    void value(T object, double doubleParameter);
}

@FunctionalInterface
public interface ObjectFloatProcedure<T> {
    void value(T object, float floatParameter);
}

@FunctionalInterface
public interface ObjectLongProcedure<T> {
    void value(T object, long longParameter);
}

@FunctionalInterface
public interface ObjectShortProcedure<T> {
    void value(T object, short shortParameter);
}

Primitive-Primitive Procedures

Side-effect operations on primitive pairs.

// Side effects on int-int pairs
package org.eclipse.collections.api.block.procedure.primitive;

@FunctionalInterface
public interface IntIntProcedure {
    void value(int argument1, int argument2);
}

// Cross-type combinations (examples):
@FunctionalInterface
public interface IntLongProcedure {
    void value(int intParameter, long longParameter);
}

@FunctionalInterface
public interface IntDoubleProcedure {
    void value(int intParameter, double doubleParameter);
}

@FunctionalInterface
public interface LongIntProcedure {
    void value(long longParameter, int intParameter);
}

// Similar interfaces exist for all meaningful primitive type combinations

Comparator Interfaces

Primitive Comparators

Efficient comparison operations for primitive types.

// Compare int values
package org.eclipse.collections.api.block.comparator.primitive;

@FunctionalInterface
public interface IntComparator {
    int compare(int o1, int o2);
}

// Similar interfaces for all primitive types:
@FunctionalInterface
public interface BooleanComparator {
    int compare(boolean o1, boolean o2);
}

@FunctionalInterface
public interface ByteComparator {
    int compare(byte o1, byte o2);
}

@FunctionalInterface
public interface CharComparator {
    int compare(char o1, char o2);
}

@FunctionalInterface
public interface DoubleComparator {
    int compare(double o1, double o2);
}

@FunctionalInterface
public interface FloatComparator {
    int compare(float o1, float o2);
}

@FunctionalInterface
public interface LongComparator {
    int compare(long o1, long o2);
}

@FunctionalInterface
public interface ShortComparator {
    int compare(short o1, short o2);
}

Usage Examples

Using Object Functions

// Transform strings to their lengths
Function<String, Integer> lengthFunction = String::length;
MutableList<String> words = Lists.mutable.with("hello", "world", "java");
MutableList<Integer> lengths = words.collect(lengthFunction);

// Multi-argument functions
Function2<String, String, String> concat = (s1, s2) -> s1 + s2;
String result = concat.value("Hello", " World"); // "Hello World"

// Zero-argument function
Function0<String> supplier = () -> "Default Value";
String value = supplier.value();

Using Predicates

// Filter even numbers
Predicate<Integer> isEven = n -> n % 2 == 0;
MutableList<Integer> numbers = Lists.mutable.with(1, 2, 3, 4, 5);
MutableList<Integer> evens = numbers.select(isEven);

// Two-argument predicate
Predicate2<String, Integer> hasMinLength = (str, minLen) -> str.length() >= minLen;
MutableList<String> words = Lists.mutable.with("a", "hello", "hi", "world");
MutableList<String> longWords = words.selectWith(hasMinLength, 4);

Using Procedures

// Print each element
Procedure<String> printer = System.out::println;
Lists.mutable.with("a", "b", "c").forEach(printer);

// Two-argument procedure
Procedure2<String, Integer> indexedPrinter = (str, index) -> 
    System.out.println(index + ": " + str);
Lists.mutable.with("a", "b", "c").forEachWithIndex(indexedPrinter);

Using Primitive Functions

// Convert objects to int values (no boxing)
IntFunction<String> stringLength = String::length;
MutableList<String> words = Lists.mutable.with("hello", "world");
MutableIntList lengths = words.collectInt(stringLength);

// Convert int values to objects
IntToObjectFunction<String> intToString = String::valueOf;
MutableIntList numbers = IntLists.mutable.with(1, 2, 3);
MutableList<String> strings = numbers.collect(intToString);

// Primitive-to-primitive transformations
IntToIntFunction square = n -> n * n;
MutableIntList numbers2 = IntLists.mutable.with(1, 2, 3, 4, 5);
MutableIntList squares = numbers2.collectInt(square);

Using Primitive Predicates

// Filter primitive collections (no boxing)
IntPredicate isEven = n -> n % 2 == 0;
MutableIntList numbers = IntLists.mutable.with(1, 2, 3, 4, 5);
MutableIntList evens = numbers.select(isEven);

// Object-primitive predicates
ObjectIntPredicate<String> hasLength = (str, len) -> str.length() == len;
MutableList<String> words = Lists.mutable.with("cat", "dog", "bird");
MutableList<String> threeLetter = words.selectWith(hasLength, 3);

Using Primitive Procedures

// Process primitive values (no boxing)
IntProcedure printer = System.out::println;
IntLists.mutable.with(1, 2, 3).forEach(printer);

// Object-primitive procedures
ObjectIntProcedure<String> indexedPrinter = (str, index) -> 
    System.out.println("Item " + index + ": " + str);
Lists.mutable.with("a", "b", "c").forEachWithIndex(indexedPrinter);

// Primitive-primitive procedures (e.g., for maps)
IntIntProcedure keyValuePrinter = (key, value) -> 
    System.out.println("Key: " + key + ", Value: " + value);
IntIntMaps.mutable.with(1, 10, 2, 20).forEachKeyValue(keyValuePrinter);

The comprehensive functional interface system in Eclipse Collections provides both type safety and performance optimization, allowing developers to write expressive functional code while maintaining efficiency through primitive specializations.

Install with Tessl CLI

npx tessl i tessl/maven-org-eclipse-collections--eclipse-collections-api

docs

core-collections.md

factories-utilities.md

functional-interfaces.md

index.md

maps-multimaps.md

primitive-collections.md

tile.json