Elm Record Type — Tentamen Software Testing Blog


In the previous post, we learned about the Elm application state so users could interact with our Picshare application. Today we explain Elm Record Type, an Elm implementation of key/value data pairs. This post is part of the functional language series, and it is based on a remarkable book Programming Elm Build Safe and Maintainable Front-End Applications by Jeremy Fairbank.

Elm Record

Let’s create a comedian record in elm repl:

Note that elm repl always return data type, in comedian case, all values are Strings. With . notation, we can get key value. But as Elm is immutable, we can not add to comedian new key or assign to the existing key new value (explore Elm Record image above).

Create Record

Let’s create a function that will have as input and output parameter record type. The function will use input record to create a new instance of output record. The function adds to comedian wealth fixed income of 1 000 000.

The second definition of income the function is using update notatation using | operator. With this syntax, we write less boilerplate code.

Benefits Of Immutability

There is a high chance that you will need to edit somebody else code. You will use debugging or unit tests to grasp how a function works.

With immutability, your job is much easier because each function returns new data. You can forget about input data and concentrate on function output data.


  • Elm Record Syntax
  • How To Create Record
  • How To Update Record
  • Why Record Is Immutable

Originally published at https://blog.tentamen.eu on August 22, 2020.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store