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
Changes from 2 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
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