// Path: src/main/java/com/github/martincooper/datatable/TransformCollector.java
// public static <T, U> TransformCollector<T, U> transform(Function<Stream<T>, U> function) {
//     return new TransformCollector<>(function);
// }


import io.vavr.collection.*;
import io.vavr.control.Try;
import java.util.Iterator;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import static com.github.martincooper.datatable.TransformCollector.transform;
package com.github.martincooper.datatable;




/**
 * DataRowCollectionBase. Handles a collection of DataRows
 * Created by Martin Cooper on 17/07/2017.
 */
abstract class DataRowCollectionBase implements Iterable<DataRow> {

    protected final DataTable table;
    protected final Vector<DataRow> rows;

    /**
     * Protected DataRow constructor.
     * Use 'build' to create instance.
     *
     * @param table The DataTable the DataRow is pointing to.
     * @param rows The DataRows.
     */
    DataRowCollectionBase(DataTable table, Iterable<DataRow> rows) {
        this.table = table;
        this.rows = Vector.ofAll(rows);
    }

    /**
     * Returns an iterator over elements of DataRow.
     *
     * @return an Iterator.
     */
    @Override
    public Iterator<DataRow> iterator() {
        return rows.iterator();
    }

    /**
     * Returns the Data Row at the specified index.
     *
     * @param rowIndex The row index.
     * @return Returns the Data Row.
     */
    public DataRow get(Integer rowIndex) {
        return this.rows.get(rowIndex);
    }

    /**
     * The number of rows in the collection.
     *
     * @return Returns the number of rows.
     */
    public Integer rowCount() {
        return this.rows.length();
    }

    /**
     * Returns access to the Data Row collection as a sequence of Data Rows.
     *
     * @return Returns the rows.
     */
    public Seq<DataRow> asSeq() {
        return this.rows;
    }

    /**
     * Filters the row data using the specified predicate,
     * returning the results as a DataView over the original table.
     * @param predicate The filter criteria.
     * @return Returns a DataView with the filter results.
     */
    public DataView filter(Predicate<DataRow> predicate) {
        return this.rows
                .filter(predicate)
// Path: src/main/java/com/github/martincooper/datatable/TransformCollector.java
// public static <T, U> TransformCollector<T, U> transform(Function<Stream<T>, U> function) {
//     return new TransformCollector<>(function);
// }


// Path: src/main/java/com/github/martincooper/datatable/DataRowCollectionBase.java
import io.vavr.collection.*;
import io.vavr.control.Try;
import java.util.Iterator;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import static com.github.martincooper.datatable.TransformCollector.transform;

package com.github.martincooper.datatable;




/**
 * DataRowCollectionBase. Handles a collection of DataRows
 * Created by Martin Cooper on 17/07/2017.
 */
abstract class DataRowCollectionBase implements Iterable<DataRow> {

    protected final DataTable table;
    protected final Vector<DataRow> rows;

    /**
     * Protected DataRow constructor.
     * Use 'build' to create instance.
     *
     * @param table The DataTable the DataRow is pointing to.
     * @param rows The DataRows.
     */
    DataRowCollectionBase(DataTable table, Iterable<DataRow> rows) {
        this.table = table;
        this.rows = Vector.ofAll(rows);
    }

    /**
     * Returns an iterator over elements of DataRow.
     *
     * @return an Iterator.
     */
    @Override
    public Iterator<DataRow> iterator() {
        return rows.iterator();
    }

    /**
     * Returns the Data Row at the specified index.
     *
     * @param rowIndex The row index.
     * @return Returns the Data Row.
     */
    public DataRow get(Integer rowIndex) {
        return this.rows.get(rowIndex);
    }

    /**
     * The number of rows in the collection.
     *
     * @return Returns the number of rows.
     */
    public Integer rowCount() {
        return this.rows.length();
    }

    /**
     * Returns access to the Data Row collection as a sequence of Data Rows.
     *
     * @return Returns the rows.
     */
    public Seq<DataRow> asSeq() {
        return this.rows;
    }

    /**
     * Filters the row data using the specified predicate,
     * returning the results as a DataView over the original table.
     * @param predicate The filter criteria.
     * @return Returns a DataView with the filter results.
     */
    public DataView filter(Predicate<DataRow> predicate) {
        return this.rows
                .filter(predicate)
                .collect(transform(rows -> DataView.build(this.table, rows).get()));