Intro to lenses in Swift: Immutability of objects

, Software Pundits
This post was originally published on this site

Apium Hub

To understand lenses in Swift, we should first review what we refer to when talking about immutability of an object.

We understand as an immutable object that object which can not be modified once it is created.

Its use gives us great advantages such as the reliability that our object has not undergone changes throughout the execution of the program, as well as its quality of thread-safe allowing us to access them concurrently without consequences.

Intro to lenses in Swift: Immutability of objects The Lenses

The lenses provide an elegant way to update immutable states of an object. A lens, as the name suggests, allows us to zoom in a particular part of the structure of an object
to obtain, modify or enter a new value.

We could define them as functional getters and setters.

In the implementation of the lenses in Swift we will see that we have a whole object ( Whole ) and

To read the full article click on the 'post' link at the top.