aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2020-01-11 20:35:56 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2020-01-11 21:31:20 +0100
commit4ede11a75f37bb35d384fc9ce95231671e18acf3 (patch)
tree3cea18e0917625473d95ce9c02847a9bcbc93078 /data
parent23d81081d0d69c59ee3861bb4b7fb132efa03d6b (diff)
downloadpandoc-4ede11a75f37bb35d384fc9ce95231671e18acf3.tar.gz
Lua: add methods `insert`, `remove`, and `sort` to pandoc.List
The functions `table.insert`, `table.remove`, and `table.sort` are added to pandoc.List elements. They can be used as methods, e.g. local numbers = pandoc.List {2, 3, 1} numbers:sort() -- numbers is now {1, 2, 3}
Diffstat (limited to 'data')
-rw-r--r--data/pandoc.List.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/data/pandoc.List.lua b/data/pandoc.List.lua
index f5b118965..b33c30876 100644
--- a/data/pandoc.List.lua
+++ b/data/pandoc.List.lua
@@ -104,6 +104,12 @@ function List:includes (needle, init)
return not (List.find(self, needle, init) == nil)
end
+--- Insert an element into the list. Alias for `table.insert`.
+-- @param list list
+-- @param[opt] pos position at which the new element is to be inserted
+-- @param value value to insert
+List.insert = table.insert
+
--- Returns a copy of the current list by applying the given function to
-- all elements.
-- @param fn function which is applied to all list items.
@@ -115,6 +121,17 @@ function List:map (fn)
return res
end
+--- Remove element from list (alias for `table.remove`)
+-- @param list list
+-- @param[opt] pos position of the element to be removed (default: #list)
+-- @return the removed element
+List.remove = table.remove
+
+--- Sort list in-place (alias for `table.sort`)
+-- @param list list
+-- @param[opt] comp comparison function; default to `<` operator.
+List.sort = table.sort
+
-- Set metatable with __call metamethod. This allows the use of `List`
-- as a constructor function.
local ListMT = {