summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/common.lua23
1 files changed, 23 insertions, 0 deletions
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)
39 return result 39 return result
40end 40end
41 41
42function pandoc.List:filterMap(fn)
43 local mapped = self:map(fn)
44 local result = pandoc.List()
45
46 for i = 1, #mapped do
47 local val = mapped[i]
48 if val then
49 result:insert(val)
50 end
51 end
52
53 return result
54end
55
42function pandoc.List:take(n) 56function pandoc.List:take(n)
43 if n >= #self then return self end 57 if n >= #self then return self end
44 58
@@ -59,6 +73,15 @@ function pandoc.List:skip(n)
59 return result 73 return result
60end 74end
61 75
76function pandoc.List:shuffle()
77 for i = #self, 2, -1 do
78 local j = math.random(i)
79 self[i], self[j] = self[j], self[i]
80 end
81
82 return self
83end
84
62return { 85return {
63 dump = dump 86 dump = dump
64} 87}