I have this Java 8 code:
Contact contact = new Contact("");
for (ContactEvent event : events) {
contact = contact.apply(event);
}
and I want to transform it to be functional using Stream.reduce
method. I have tried this:
Contact contact = events.stream()
.reduce(new Contact(""),
(contact1, contactEvent) -> contact1.apply(contactEvent), //Ok!
(contact12, contact2) -> null); //I don't want this!
Why do I have to combine two Contact
s? What am I supposed to do in the combiner?
If I return null
, like above, it works fine. And debugger does not even execute that line (return null
).