We've already seen several of Reason's primitive data structures including strings, integers, floats, tuples, records, and variants. Let's explore a few more.
Data structures
Array
Reason arrays compile to regular JavaScript arrays. Reason arrays are as follows:
- Homogeneous (all elements must be of the same type)
- Mutable
- Fast at random access and updates
They look like this:
let array = [|"first", "second", "third"|];
Accessing and updating elements of an array are the same as in JavaScript:
array[0] = "updated";
In JavaScript, we map over the array, as follows:
/* JavaScript */
array.map(e => e + "-mapped")
To do the same in Reason, we have a few different...