Elm Record Type — Tentamen Software Testing Blog

Image for post
Image for post
Elm Record

TL;DR

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.

Image for post
Image for post
Create Elm Record

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.

Remember

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

Written by

Founder of Tentamen, software testing agency.

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