RosettaCodeData/Task/Nested-templated-data/Pluto/nested-templated-data.pluto

21 lines
686 B
Plaintext

require "map"
local fmt = require "fmt" -- v1.0.1 or higher
local function with_payload(template, payload, used)
return template:mapped( |item| -> do
if type(item) == "table" then
return with_payload(item, payload, used)
else
used:insert(item)
return $"'{payload[item + 1]}'"
end
end)
end
local p = {"Payload#0", "Payload#1", "Payload#2", "Payload#3", "Payload#4", "Payload#5", "Payload#6"}
local t = {{{1, 2}, {3, 4, 1}, 5}}
local used = {}
fmt.lprint(with_payload(t, p, used))
local unused = set.of(range(0, 6):unpack()):except(set.of(used:unpack()))
fmt.print("\nThe unused payloads have indices of %s.", unused)