Closed davidak09 closed 6 years ago
Interesting, it seems like a reasonable trade-off between code complexity and usability.
This could be probably also applied to generic type builders, eg.: ReduceByKey
cc @VaclavPlajt
static <IN> KeyBuilder<IN>of(Dataset<IN> input) {
// ...
}
interface KeyBuilder<IN> {
<K> ReduceBuilder<IN, K> keyBy(UnaryFunction<IN, K> keyExtractor);
}
interface ReduceBuilder<IN, K> {
<OUT> FinalBuilder<IN, K, OUT> keyBy(ReduceFunctor<IN, OUT> reducer);
}
interface FinalBuilder<IN, K, OUT> {
// optinal builders
}
class Builder<IN, K, OUT> extends KeyBuilder<IN>, ReduceBuilder<IN, K>, FinalBuilder<IN, K, OUT> {
}
That is a clever solution to our builders problem. I elaborated little bit more. And it seem to suit to our needs. See an example.
@VaclavPlajt awesome, this should simplify things a lot
I found some solution to the builder problem, so here's an enhancement proposal. It looks more readable, at least to me. :-)
Inspiration taken from: https://blog.jayway.com/2012/02/07/builder-pattern-with-a-twist/