O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Importance of Immutability

In object-oriented and functional programming, immutable objects are objects whose state cannot be changed or altered after they are initiated. Therefore, a mutable object stays the same until the end of its life cycle, when it is de-initialized. In contrast, a mutable object can be altered countless times by other objects after it is initiated.

Immutable objects improve readability and runtime efficiency, and using them simplifies our applications.

This chapter will cover the concept of immutability by discussing the following topics with coding examples:

  • Immutability
  • Benefits of immutability
  • Cases for mutability
  • An example with approach comparisons
    • Side-effects and unintended consequences
    • Testability
  • Copy ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required