Skip to content

Document array spreads #810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions compilers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion compilers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"rescript-1000": "npm:rescript@10.0.0",
"rescript-1010": "npm:rescript@10.1.0",
"rescript-1100": "npm:rescript@11.0.0",
"rescript-1110": "npm:rescript@11.1.0-rc.1",
"rescript-1110": "npm:rescript@11.1.0-rc.2",
"rescript-820": "npm:bs-platform@8.2.0",
"rescript-902": "npm:bs-platform@9.0.2",
"rescript-912": "npm:rescript@9.1.2"
Expand Down
48 changes: 48 additions & 0 deletions pages/docs/manual/latest/array-and-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,54 @@ var pushedValue = myArray.push("bye");

</CodeTab>

### Array spreads

**Since 11.1**


You can spread arrays of the the same type into new arrays, just like in JavaScript:

<CodeTab labels={["ReScript", "JS Output"]}>

```res example
let y = [1, 2]
let x = [4, 5, ...y]
let x2 = [4, 5, ...y, 7, ...y]
let x3 = [...y]
```

```javascript
var Belt_Array = require("rescript/lib/js/belt_Array.js");

var y = [
1,
2
];

var x = Belt_Array.concatMany([
[
4,
5
],
y
]);

var x2 = Belt_Array.concatMany([
[
4,
5
],
y,
[7],
y
]);

var x3 = Belt_Array.concatMany([y]);
```
</CodeTab>

> Note that array spreads compiles to `Belt.Array.concatMany` right now. This is likely to change to native ES6 array spreads in the future.

## List

ReScript provides a singly linked list too. Lists are:
Expand Down