fuzzycsv.Reducer.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fuzzy-csv Show documentation
Show all versions of fuzzy-csv Show documentation
A groovy/java tabular Data (from CSV,SQL,JSON) processing library that supports fuzzy column matching,tranformations/merging/querying etc
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)
}
}