com.ajjpj.afoundation.collection.immutable.ATraversable Maven / Gradle / Ivy
package com.ajjpj.afoundation.collection.immutable;
import com.ajjpj.afoundation.function.*;
/**
* This interface represents collections that can be traversed "as whole" but not necessarily stepwise. Persistent collections
* are typical examples of this: They require cleanup (resource deallocation) after iterating is through, and exporting a
* java.util.Iterator
can not guarantee that.
*
* @author arno
*/
public interface ATraversable extends AMonadicOps {
/**
* Executes the statement {@code f} for each element of the {@code ATraversable}.
*/
void foreach(AStatement1 super T, E> f) throws E;
@Override ATraversable filter(APredicate super T, E> pred) throws E;
@Override ATraversable map(AFunction1 super T, ? extends X, E> f) throws E;
@Override ATraversable flatMap(AFunction1 super T, ? extends Iterable, E> f) throws E;
@Override ATraversable collect (APartialFunction super T, ? extends X, E> pf) throws E;
/**
* This method 'folds' the elements of this collection into a single value. It iterates over the elements, passing the
* intermediate result and the element to the aggregation function {@code f}.
*
* For example, if this collections holds elements of type Integer, you could compute the sum of all elements by calling
* {@code foldLeft (0, (x,y) -> x+y); }.
*
* @param startValue initial value that is used to initialize the intermediate result
* @param f the aggregation function
* @return the resulting value of the aggregation
*/
R foldLeft(R startValue, AFunction2 f) throws E;
@Override AOption find(APredicate super T, E> pred) throws E;
@Override ATraversable flatten();
@Override boolean forAll(APredicate super T, E> pred) throws E;
@Override boolean exists(APredicate super T, E> pred) throws E;
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy