import java.util.stream.Stream;
public class Test {
public static void main(String args[]) {
Stream.of(1, 2, 3, 4, 5).map(i -> new Pair(i, i)).reduce(
new Pair(0, 0),
(acc, pair) -> new Pair(acc.fst + pair.fst, acc.snd + pair.snd)
);
System.out.println(Stream.of(1, 2, 3, 4, 5).reduce(
new Pair(0, 0),
Pair::add,
Pair::combine
));
}
}
public class Pair {
public final int fst;
public final int snd;
public Pair(int fsn, int snd) {
this.fst = fsn;
this.snd = snd;
}
public Pair add(int i) {
return new Pair(fst + i, snd + i);
}
public Pair combine(Pair target) {
return new Pair(fst + target.fst, target.snd);
}
@Override
public String toString() {
return "(" + fst + ", " + snd + ')';
}
}