Merge branch 'tuple-destructuring' into 'dev'

Tuple destructuring description

See merge request ligolang/ligo!545
This commit is contained in:
Sander 2020-04-14 11:49:18 +00:00
commit 313afab565

View File

@ -59,6 +59,52 @@ let full_name : full_name = ("Alice", "Johnson");
</Syntax>
<Syntax syntax="cameligo">
### Destructuring
If we want to get the first and last name of the `full_name` type, we can use
destructuring. Destructuring a tuple allows you to give names to the elements
inside the tuple.
```cameligo group=tuple
let (first_name, last_name) : full_name = full_name
```
This also works in functions:
```cameligo group=tuple
let first_name ((first_name, _): full_name) = first_name
let alice = first_name full_name
```
Notice that we use the underscore to indicate that we ignore the last element
of the tuple.
</Syntax>
<Syntax syntax="reasonligo">
### Destructuring
If we want to get the first and last name of the `full_name` type, we can use
destructuring. Destructuring a tuple allows you to give names to the elements
inside the tuple.
```reasonligo group=tuple
let (first_name, last_name) : full_name = full_name
```
This also works in functions:
```reasonligo group=tuple
let first_name = ((first_name, _): full_name) => first_name
let alice = first_name(full_name)
```
Notice that we use the underscore to indicate that we ignore the last element
of the tuple.
</Syntax>
### Accessing Components