ucg/std/tuples.ucg
Jeremy Wall 890387b4cc FEATURE: Macros are just an expression now.
This is a breaking change for the map, filter, and reduce expressions
but happily a forward compatible change for macros themselves.
2019-01-16 19:27:58 -06:00

34 lines
725 B
Plaintext

// return a list of the fields in a tuple.
let fields = module{
tpl = NULL,
} => {
let reducer = macro(acc, field, value) => acc + [field];
let result = reduce reducer [], (mod.tpl);
};
// return a list of the values in a tuple.
let values = module{
tpl = NULL,
} => {
let reducer = macro(acc, field, value) => acc + [value];
let result = reduce reducer [], (mod.tpl);
};
let iter = module{
tpl = NULL,
} => {
let reducer = macro(acc, field, value) => acc + [[field, value]];
let result = reduce reducer [], (mod.tpl);
};
let strip_nulls = module{
tpl = NULL,
} => {
let filterer = macro(name, value) => value != NULL;
let result = filter filterer (mod.tpl);
};