Skip to content

Commit 16aca1d

Browse files
committed
document array spreads available in v11.1
1 parent a569345 commit 16aca1d

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

pages/docs/manual/latest/array-and-list.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,54 @@ var pushedValue = myArray.push("bye");
5050

5151
</CodeTab>
5252

53+
### Array spreads
54+
55+
**Since 11.1**
56+
57+
58+
You can spread arrays of the the same type into new arrays, just like in JavaScript:
59+
60+
<CodeTab labels={["ReScript", "JS Output"]}>
61+
62+
```res example
63+
let y = [1, 2]
64+
let x = [4, 5, ...y]
65+
let x = [4, 5, ...y, 7, ...y]
66+
let x = [...y]
67+
```
68+
69+
```javascript
70+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
71+
72+
var y = [
73+
1,
74+
2
75+
];
76+
77+
var x = Belt_Array.concatMany([
78+
[
79+
4,
80+
5
81+
],
82+
y
83+
]);
84+
85+
var x2 = Belt_Array.concatMany([
86+
[
87+
4,
88+
5
89+
],
90+
y,
91+
[7],
92+
y
93+
]);
94+
95+
var x3 = Belt_Array.concatMany([y]);
96+
```
97+
</CodeTab>
98+
99+
> Note that array spreads compiles to `Belt.Array.concatMany` right now. This is likely to change to native ES6 array spreads in the future.
100+
53101
## List
54102

55103
ReScript provides a singly linked list too. Lists are:

0 commit comments

Comments
 (0)