Testability

Our mutable example's addNewProduct() method has no return values. While it is possible to write a unit test for it, it is not obvious how we should implement asserting because the method causes a side-effect in our existing instance that we need to know about.

Our immutable example's addNewProduct() method returns a new array of product. We simply inspect the value of products and assert. We still have both the old and new instances, so we have everything we need to ensure that our code works as intended.

Although we do not cover unit-testing in this book, it is highly recommended that you explore QuickCheck-based libraries such as Quick (https://github.com/Quick/Quick) and SwiftCheck (https://github.com/typelift/SwiftCheck) as they employ FP techniques to ease the unit testing process of our applications.