I have the following code, and I'd like to refactor it to a more functional way:
public void processPersons(List<Person> personList) {
for (Person person : personList) {
Integer addressId = createAddress(person);
if (addressId != null) {
updateDbStatus(addressId, person);
}
}
}
How do I convert the above to a more functional style of programming?
map()
\$\endgroup\$personList.forEach(person -> Optional.ofNullable(createAddress(person)).ifPresent(addressId -> updateDbStatus(addressId, person)));
, but I wouldn't recommend it. The code you have now is better in my opinion. \$\endgroup\$