diff options
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/common.lua | 23 |
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 |
40 | end | 40 | end |
41 | 41 | ||
42 | function 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 | ||
54 | end | ||
55 | |||
42 | function pandoc.List:take(n) | 56 | function 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 |
60 | end | 74 | end |
61 | 75 | ||
76 | function 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 | ||
83 | end | ||
84 | |||
62 | return { | 85 | return { |
63 | dump = dump | 86 | dump = dump |
64 | } | 87 | } |