io.github.vmzakharov.ecdataframe.dataframe.DfIterate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dataframe-ec Show documentation
Show all versions of dataframe-ec Show documentation
A tabular data structure based on the Eclipse Collections framework
The newest version!
package io.github.vmzakharov.ecdataframe.dataframe;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.impl.factory.Lists;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
/**
* An interface defining common iteration patterns for data frames and data frame indices
*/
public interface DfIterate
{
/**
* Executes the procedure for each row in this dataframe iterable
*
* @param action the procedure to execute for each row
*/
void forEach(Procedure action);
/**
* Creates a list from this dataframe iterable. The new collection is made up of the results of applying
* the specified function to each row of the data frame iterable.
*
* @param action the function the result of which will be collected in the resulting collection
* @param the type of the elements of the resulting collection
* @return the list made up of the results of applying the specified action to each row of the data frame iterable
*/
default ListIterable collect(Function action)
{
return this.collect(
Lists.mutable::empty,
(container, row) -> container.add(action.valueOf(row))
);
}
/**
* Performs a reduction operation on each row of the data frame iterable with the results accumulating in the
* container provided by the supplier parameter.
* @param supplier supplies the result container
* @param accumulator a two argument function that takes the result container and the current row of the data frame
* iterable
* @return the result container
* @param the type of the result reduction operation (result container)
*/
default R collect(Supplier extends R> supplier, BiConsumer accumulator)
{
R result = supplier.get();
this.forEach(row -> accumulator.accept(result, row));
return result;
}
}