~mna/tulip

The tulip.xtable module contains table functions that extend Lua's standard table module.

#API

Assuming local xtable = require 'tulip.xtable'.

#t = xtable.merge(...)

The merge function merges an arbitrary number of tables into the first table, in the order provided (rightmost table wins). To leave existing tables unchanged, pass a new table as first value. If the last value is a function, it is used as filter to select the fields to merge, and receives the destination table, source table, key and value as arguments, and accepts the key-value pair if it returns true.

It returns the destination table (the first provided table), or nil if no table is provided.

#t = xtable.setdiff(...)

Returns the difference of the first set with all other sets, i.e. a set with only the keys found in the first but not in either of the other sets. The values are set to true. Returns nil if no table is provided.

#t = xtable.setinter(...)

Returns the intersection of all sets, i.e. a set with only keys found in all sets. The values are set to the number of sets. Returns nil if no table is provided.

#t = xtable.setunion(...)

Returns the union of all the sets. The value is the number of sets in which the key was found. Returns nil if no table is provided.

#t = xtable.toarray(...)

Turns a list of tables (most likely sets) into an array, adding each key of each table in the resulting array. The order is undefined. Returns nil if no table is provided.

#t = xtable.toset(...)

Turns an array into a set, where each value in the array becomes a key and the value is the number of times the key was found in the array (which also behaves as a truthy value if the only goal is to check if it was present). If multiple arrays are provided, the set is the union of all arrays. Returns nil if no array is provided.

Back to index

About this wiki

commit 3ebfbd288b8e5c95fdf8ce2027a0e94cfa1c8976
Author: Martin Angers <martin.n.angers@gmail.com>
Date:   2021-02-25T14:07:12-05:00

Update to reflect Request:validate_body
Clone this wiki
https://git.sr.ht/~mna/tulip-wiki (read-only)
git@git.sr.ht:~mna/tulip-wiki (read/write)