November 15, 2018

What is Record in Elm ?

Record

These are some intersting aspect that are different from other programing language.

  • You cannot ask for a field that does not exist.
  • No field will ever be undefined or null.
  • You cannot create recursive records with a this or self keyword.

Creating new object

To update field in the record, which means creating a new object from an object.

You can do it as follows:

{ model | keywords = model.keywords ++ [ model.newKeyword ] };

If you want to change multiple fields, you can specify it with a comma.

{ model | keywords = model.keywords ++ [ model.newKeyword ], newKeyword = "" };

Access

There are few different ways to actually access to the model.

model.keywords;
.keywords model;

The keyword can act like a function. Pretty cool.

Written by...
Kazushi Kawamura
Software Engineer based in Tokyo.
2019 © Kazushi Kawamura.