Immutable Data
Explore the concept of immutable data in Elixir and understand why values cannot be altered once set. Learn how this immutability improves code reliability, makes concurrency safer, and changes the way data transformations are handled within Elixir programs.
We'll cover the following...
If we listen to functional programming experts, we’ll hear them make a big deal about immutability, which is the fact that in a functional program, data cannot be altered once created. And, indeed, Elixir enforces immutable data. But why?
Let’s forget about Elixir for a moment and think about our current programming language of choice. Let’s imagine we wrote this:
count = 99
do_something_with(count)
print(count)
We’d expect it to output 99. In fact, we’d be very surprised if it didn’t. We believe that count will always have the value ...