Factory chapter: code refactoring suggestion

Quick suggestion while reading the book, I am a big fan of Swift compactMap function and on page 178 (the factory chapter) you could have refactor the addAnnotations method as follow:

  private func addAnnotations() {
    let annotations = businesses.compactMap({annotationFactory.createBusinessMapViewModel(for: $0)})



1 Like

@giguerea Thanks very much for your suggestion! The nature of programming is such that, there is definitely more than one way to skin a cat! The question arises, is the approach you’re using accomplishing your goal, using minimal code, that is understandable, and easy to read? If the answer is “yes” then more power to you! :slight_smile: