Elixir vs. Mutable Objects

Learn about mutations in Elixir and how we can use Elixir as an object-oriented language.

Since Elixir is a functional programming language, it doesn’t have objects. The language also has a strong focus on immutability. In Elixir, we transform data rather than mutate it. Said another way, OO (object-oriented) changes. FP (functional programming) copies. Basically, OO mutates while FP doesn’t.

Even though this difference may be subtle and might even seem inefficient, it’s transformational. Many of Elixir’s most important benefits flow directly from this design decision. In this section, we look at what those benefits might be, and why they matter.

Understanding mutation

Mutable objects bundle three concerns that are distinct in Elixir:

  • State
  • Behavior
  • Time

Take this example:

  dictionary.store("key", "value")

Get hands-on with 1400+ tech skills courses.