Skip to content
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

add usage fst and snd for tuple #663

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions pages/docs/manual/latest/tuple.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ var y = 30.5;

</CodeTab>

To get first or second member of a tuple, use `fst` or `snd` function:

<CodeTab labels={["ReScript", "JS Output"]}
```res example
let tup = (1, "ReScript")
let f = tup->fst
let s = tup->snd
```
```js
var tup = [
1,
"ReScript"
];
var f = 1;
var s = "ReScript";
```
</CodeTab>

The `_` means you're ignoring the indicated members of the tuple.

Tuples aren't meant to be updated mutatively. You'd create new ones by destructuring the old ones:
Expand Down