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

com.ajjpj.afoundation.collection.immutable.ATraversable Maven / Gradle / Ivy

There is a newer version: 1.0-pre19
Show newest version
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 f) throws E;

    @Override  ATraversable filter(APredicate pred) throws E;
    @Override  ATraversable map(AFunction1 f) throws E;
    @Override  ATraversable flatMap(AFunction1, E> f) throws E;
    @Override  ATraversable collect (APartialFunction 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 pred) throws E; @Override ATraversable flatten(); @Override boolean forAll(APredicate pred) throws E; @Override boolean exists(APredicate pred) throws E; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy