Lesson 6. Working with immutable data

 

Working with immutable data is one of the more difficult aspects of functional programming to deal with, but as it turns out, after you get over the initial hurdle, you’ll be surprised just how easy it is to write entire applications working with purely immutable data structures. It also goes hand in hand with many other F# features you’ll see, such as expression-based development. In this lesson, you’ll learn

  • The basic syntax for working with immutable and mutable data in F#
  • Some reasons you should consider immutability by default in software development today
  • Simple examples of working with immutable values to manage changing state

6.1. Working with mutable data—a recap

Let’s start by thinking about some of the issues we come up against but often take for granted as simply “the way things are.” Here are a few examples that I’ve either seen firsthand or fallen foul of myself.

6.1.1. The unrepeatable bug

6.2. Being explicit about mutation

6.3. Modeling state

Summary