Updating persons in database with newly created addresses I have the following code, and I'd like to refactor it to a more functional way:

public void processPersons(List&lt;Person&gt; 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?
One of variants is to have PersonWithAddress subclass with created addressIp:

    persons
            .stream()
            .map(PersonWithAddress::new)
            .forEach(this::updateDbStatus);


You call updateDbStatus where check the address for null:

void updateDbStatus(PersonWithAddress personWithAddress) {
    if (personWithAddress.getAddressIp() != null) {
        // do the update
    }
}


Model classes like these ones:

class Person{
    Person(final Person original) {
        // copy constructor
    }
}

class PersonWithAddress extends Person {
    private final Integer addressIp;

    PersonWithAddress(final Person person) {
        super(person);
        this.addressIp = createAddress();
    }

    Integer getAddressIp() {
        return addressIp;
    }

    private Integer createAddress() {
        // have a logic to create an address
        return 0;
    }
}