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

fuzzycsv.Reducer.groovy Maven / Gradle / Ivy

Go to download

A groovy/java tabular Data (from CSV,SQL,JSON) processing library that supports fuzzy column matching,tranformations/merging/querying etc

There is a newer version: 1.9.1-groovy4
Show newest version
package fuzzycsv
/**
 * Created by kay on 9/9/2016.
 */
class Reducer extends AbstractAggregator {

    Closure reducer
    private passRecord

    Reducer(Closure reducer) {
        this.reducer = reducer
        this.passRecord = reducer.maximumNumberOfParameters > 1
    }


    @Override
    Object getValue() {
        return reducer.call(data)
    }

    Object getValue(Record fx) {

        if (passRecord) {
            reducer.call(data, fx)
        } else {
            return reducer.call(data)
        }
    }

    static reduce(Closure fx) {
        return new Reducer(fx)
    }

    static reduce(String column, Closure fx) {
        return new Reducer(fx).az(column)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy