From 9acab4200ad454a030edefd0f41e39b3e4936c84 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Thu, 4 Aug 2022 21:27:32 +0200 Subject: Improved metadata processing --- scripts/lib/common.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'scripts/lib') diff --git a/scripts/lib/common.lua b/scripts/lib/common.lua index 5ed3e31..ee7c6aa 100644 --- a/scripts/lib/common.lua +++ b/scripts/lib/common.lua @@ -39,6 +39,20 @@ function pandoc.List:flatMap(fn) return result end +function pandoc.List:filterMap(fn) + local mapped = self:map(fn) + local result = pandoc.List() + + for i = 1, #mapped do + local val = mapped[i] + if val then + result:insert(val) + end + end + + return result +end + function pandoc.List:take(n) if n >= #self then return self end @@ -59,6 +73,15 @@ function pandoc.List:skip(n) return result end +function pandoc.List:shuffle() + for i = #self, 2, -1 do + local j = math.random(i) + self[i], self[j] = self[j], self[i] + end + + return self +end + return { dump = dump } -- cgit v1.2.3-70-g09d2