Using the following query I get a list of arrays. I want to flatten these arrays into one array and remove duplicates. Not sure what built in functions are available.
${query[[
from index.tag "page"
where name:startsWith("Journal/")
select {
Tags = _.tags
}
]]}
Here is my best failed attempt
${query[[
from index.tag "page"
where name:startsWith("Journal/")
select {
Tags = utils.unique(utils.flatten(_.tags))
}
]]}
-- Flattens a list of lists into a single list
function utils.flatten(list_of_lists)
local flat = {}
for _, sublist in ipairs(list_of_lists) do
for _, value in ipairs(sublist) do
table.insert(flat, value)
end
end
return flat
end
-- Removes duplicates from a list while preserving order
function utils.unique(list)
local seen = {}
local result = {}
for _, value in ipairs(list) do
if not seen[value] then
seen[value] = true
table.insert(result, value)
end
end
return result
end