Copy constructors and lenses

After examining our immutable example implementation, we are not able to say that it covers all the functionalities of the imperative approach. For instance, it does not provide us with a way to change the producer of a product. After all, we cannot change it.

Whenever we need to change any property of the product, we need to go through the following process:

let mexBananas = FunctionalProduct(name: bananas.name, 
price: bananas.price,
quantity: bananas.quantity,
producer: Producer(name: "XYZ",
address: "New
Mexico, Mexico"))

This solution is verbose and does not look nice. Let's examine how we can improve this process.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset