2019-01-13 21:25:15 -06:00
|
|
|
+++
|
|
|
|
title = "UCG Tuple Modules"
|
|
|
|
weight = 2
|
|
|
|
sort_by = "weight"
|
|
|
|
in_search_index = true
|
|
|
|
+++
|
|
|
|
|
|
|
|
The UCG tuples modules can be imported like so `let t = import "std/tuples.ucg";`
|
|
|
|
and contains a number of useful operations on tuples.
|
|
|
|
|
|
|
|
## fields
|
|
|
|
|
|
|
|
The `fields` module retrieves all the field names in a tuple. It has one
|
|
|
|
parameter.
|
|
|
|
|
|
|
|
* `tpl` which is required and is the tuple to process.
|
|
|
|
|
|
|
|
```
|
|
|
|
let tpl = import "std/tuples.ucg";
|
2019-02-24 08:47:00 -06:00
|
|
|
tpl.fields{tpl={foo=1, bar=2}} == ["foo", "bar"];
|
2019-01-13 21:25:15 -06:00
|
|
|
```
|
|
|
|
|
|
|
|
## values
|
|
|
|
|
|
|
|
The `values` module retrieves all the values in a tuple. It has one parameter.
|
|
|
|
|
|
|
|
* `tpl` which is required and is the tuple to process.
|
|
|
|
|
|
|
|
```
|
|
|
|
let tpl = import "std/tuples.ucg";
|
2019-02-24 08:47:00 -06:00
|
|
|
tpl.values{tpl={foo=1, bar=2}} == [1, 2];
|
2019-01-13 21:25:15 -06:00
|
|
|
```
|
|
|
|
|
|
|
|
## iter
|
|
|
|
|
|
|
|
The `iter` module retrieves a list of all the field and value pairs in a tuple.
|
|
|
|
It has one parameter.
|
|
|
|
|
|
|
|
* `tpl` which is required and is the tuple to process.
|
|
|
|
|
|
|
|
```
|
|
|
|
let tpl = import "std/tuples.ucg";
|
2019-02-24 08:47:00 -06:00
|
|
|
tpl.enumerate{tpl={foo=1, bar=2}} == [["foo", 1], ["bar", 2]];
|
2019-01-13 21:25:15 -06:00
|
|
|
```
|