4Copyright © 2017 Albert Krewinkel
6Permission to use, copy, modify, and/or distribute this software for any purpose
7with or without fee is hereby granted, provided that the above copyright notice
8and this permission notice appear in all copies.
10THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
12FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
20-- Lua functions for pandoc scripts.
22-- @author Albert Krewinkel
23-- @copyright © 2017 Albert Krewinkel
26------------------------------------------------------------------------
40function List:__call (o)
44--- Concatenates two lists.
45function List:__concat (list)
46 local res = List.clone(self)
47 List.extend(res, list)
51--- Returns a (shallow) copy of the list.
53 local lst = setmetatable({}, getmetatable(self))
54 List.extend(lst, self)
58--- Appends the given list to the end of this list.
59function List:includes (needle)
61 if self[i] == needle then
68--- Returns the value and index of the first occurrence of the given item.
69-- @param needle item to search for
70-- @return first item equal to the needle, or nil if no such item exists.
71-- @return index of that element
72function List:find (needle, init)
73 return List.find_if(self, function(x) return x == needle end, init)
76--- Returns the value and index of the first element for which test returns true.
77-- @param test the test function
78-- @param init index at which the search is started
79-- @return first item for which `test` succeeds, or nil if no such item exists.
80-- @return index of that element
81function List:find_if (test, init)
82 init = (init == nil and 1) or (init < 0 and #self - init) or init
83 for i = init, #self do
84 if test(self[i], i) then
91--- Add the given list to the end of this list.
92-- @param list list to appended
93function List:extend (list)
95 self[#self + 1] = list[i]
99-- Returns a copy of the current list by applying the given function to all
101function List:map (fn)
102 local res = setmetatable({}, getmetatable(self))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list