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.
Let’s create a comedian record in
elm repl always return data type, in comedian case, all values are
. 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).
Let’s create a function that will have as
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.