|
|
第1行: |
第1行: |
| -- <nowiki> awawa
| | {{Infobox Metro |
| local libraryUtil = require('libraryUtil')
| | |Picture = MetroLough.png |
| local checkType = libraryUtil.checkType
| | |Description = 上屿线列车从车辆段内驶出 |
| local checkTypeMulti = libraryUtil.checkTypeMulti
| | |Logo = NebulaeCraft.png |
| local p = {}
| | |Name = 星云轨道交通上屿线 |
| p.__index = p
| | |Location = 星云市 |
| | |Type = 地铁 |
| | |System = 星云轨道交通 |
| | |Situation = 运营中 |
| | |Start = 西堤公园 |
| | |End = 源深路 |
| | |English = Lough Line |
| | |Code = M6线 |
| | |Structure = 地下 |
| | |Length = 7.91km (4.92mi) |
| | |Speed = 80千米/小时 |
| | |Lines = 2条 |
| | |Stations = 15个 |
| | |Gauge = 1,435毫米(准轨) |
| | |Electrification = DC 1,500V 接触网供电 |
| | |Blocking = CBTC移动自动闭塞 |
| | |Signal = 卡斯柯 Urbalis 888(ATO自动驾驶/GoA2) |
| | |Depot = 星羽路车辆段 |
| | |Model = LGA01 |
| | |Formation = 6节A型列车 |
| | |Opening = 2022年8月26日 |
| | |Extending = |
| | |Owner = 星云轨道交通集团有限公司 |
| | |Operator = 西开屿铁轨道交通运营集团有限公司 |
| | }}'''星云轨道交通上屿线'''是[[NebulaeCraft]]的一条地铁线路,是[[上屿区]]第三条规划的线路。本线路横贯[[上屿区]],为该区人民提供了更多的出行选择。 |
|
| |
|
| setmetatable(p, {
| | ==概览== |
| __call = function(_, enum)
| |
| return p.new(enum)
| |
| end
| |
| })
| |
|
| |
|
| function p.__tostring(enum)
| | 上屿线西起[[上屿区]],南至[[星岛区]]。一期工程因设计上的失误导致终点站后折返困难,客流不济等因素影响,二期延伸因此提上日程,并与一期同时开通运营。初期因施工难度等不可抗力导致星羽路车辆段延期交付,为了上屿线按期交付投入使用不得不借用浦厂存放车辆,因此增修了[[星云轨道交通上屿线|上屿线]]与[[星云轨道交通下关线|下关线]]的联络线,后因星羽路车辆段的完工这段联络线也开始了它新的用途。 |
| local dumpObject = require('Module:Logger').dumpObject
| |
| setmetatable(enum, nil)
| |
| return dumpObject(enum, {clean=true, collapseLimit=100})
| |
| end
| |
|
| |
|
| function p.__concat(lhs, rhs)
| | 上屿线的线路标识色为#75C2C8(R=117 G=194 B=200 C=42 M=3 Y=0 K=22)。 |
| if type(lhs) == 'table' and type(rhs) == 'table' then
| |
| return p.insert(lhs, rhs)
| |
| else
| |
| return tostring(lhs) .. tostring(rhs)
| |
| end
| |
| end
| |
|
| |
|
| function p.__unm(enum)
| | ====线路数据==== |
| return p.map(enum, function(x) return -x end)
| |
| end
| |
|
| |
|
| local function mathTemplate(lhs, rhs, funName, fun)
| | *运营里程:7.91km |
| checkTypeMulti('Module:Enum.' .. funName, 1, lhs, {'number', 'table'})
| | *站数:15 |
| checkTypeMulti('Module:Enum.' .. funName, 2, rhs, {'number', 'table'})
| | *规矩:1435mm |
| local res = setmetatable({}, getmetatable(lhs) or getmetatable(rhs))
| | *动力来源:1500V接触网供电 |
| | *最高速度:80km/h |
| | *地下区间:西堤公园—源深路 |
|
| |
|
| if type(lhs) == 'number' or type(rhs) == 'number' then
| | == 车辆 == |
| local scalar, vector
| |
| if type(lhs) == 'number' then
| |
| scalar = lhs
| |
| vector = rhs
| |
| else
| |
| scalar = rhs
| |
| vector = lhs
| |
| end
| |
|
| |
|
| for i = 1, #vector do
| | ==== LGA01型电动客车 ==== |
| res[i] = fun(vector[i], scalar)
| |
| end
| |
| else
| |
| assert(#lhs == #rhs, 'Tables are not equal length')
| |
| for i = 1, #lhs do
| |
| res[i] = fun(lhs[i], rhs[i])
| |
| end
| |
| end
| |
|
| |
|
| return res
| | * 代号:LGA01 |
| end
| | * 制造商:下关浦镇车辆有限公司(浦厂) |
| | * 车体材料:铝合金 |
| | * 外观:开三面窗的扁平车头,车身两侧各有一条近似绿松石色丝带。<s>并且为地铁迷保留了更大的门窗和更大的门缝。</s> |
| | * 长度:72米 |
| | * 宽度:2.4米 |
| | * 编组: 6节A型编组 |
| | * 供电方式:架空接触网受电直流1500V |
| | * 牵引系统:阿尔斯通 |
| | * 最高速度:80km/h |
|
| |
|
| function p.__add(lhs, rhs)
| | ==车站== |
| return mathTemplate(lhs, rhs, '__add', function(x, y) return x + y end)
| |
| end
| |
|
| |
|
| function p.__sub(lhs, rhs)
| | ====换乘站点==== |
| return mathTemplate(lhs, rhs, '__sub', function(x, y) return x - y end)
| |
| end
| |
|
| |
|
| function p.__mul(lhs, rhs)
| | *花见路 — 换乘[[星云轨道交通星岛线|星岛线]]、[[星云轨道交通下关线|下关线]],长通道换乘 |
| return mathTemplate(lhs, rhs, '__mul', function(x, y) return x * y end)
| | *深圳路 — 换乘[[星云轨道交通星川线|星川线]],同台换乘 |
| end
| | *星川 — 换乘[[星云轨道交通星川线|星川线]],同台换乘 |
| | *上海西路 — 换乘[[星云轨道交通环线|环线]],长通道换乘 |
| | *河南路 — 换乘[[星云轨道交通星岛线|星岛线]]、[[星云轨道交通空港线|空港线]],“L”字换乘 |
| | *中央公园 — 换乘[[星云轨道交通区域线|区域线]],长通道换乘 |
| | *东关路 — 换乘[[星云轨道交通环线|环线]],“L”字换乘 |
| | *源深路 — 换乘[[星云轨道交通中央线|中央线]],长通道换乘 |
|
| |
|
| function p.__div(lhs, rhs)
| | ====车站列表==== |
| return mathTemplate(lhs, rhs, '__div', function(x, y) return x / y end)
| | {| class="wikitable" style="text-align: center;" |
| end
| | ! style="text-align: center;border-bottom: 2px solid #75C2C8" |阶段 |
| | | ! style="text-align: center;border-bottom: 2px solid #75C2C8" |站名 |
| function p.__pow(lhs, rhs)
| | ! style="text-align: center;border-bottom: 2px solid #75C2C8" |换乘线路 |
| return mathTemplate(lhs, rhs, '__pow', function(x, y) return x ^ y end)
| | ! style="text-align: center;border-bottom: 2px solid #75C2C8" |站台类型 |
| end
| | ! style="text-align: center;border-bottom: 2px solid #75C2C8" |所在地 |
| | | |- |
| function p.__lt(lhs, rhs)
| | | rowspan="8" |一期 |
| for i = 1, math.min(#lhs, #rhs) do
| | |西堤公园 |
| if lhs[i] >= rhs[i] then
| | | |
| return false
| | |岛式 |
| end
| | | rowspan="6" |上屿区 |
| end
| | |- |
| return true
| | |市民广场 |
| end
| | | |
| | | |岛式 |
| function p.__le(lhs, rhs)
| | |- |
| for i = 1, math.min(#lhs, #rhs) do
| | |花见路 |
| if lhs[i] > rhs[i] then
| | |<font color="17C123">█</font> [[星云轨道交通星岛线|星岛线]] <font color="D80169">█</font> [[星云轨道交通下关线|下关线]] |
| return false
| | |岛式 |
| end
| | |- |
| end
| | |凌河路 |
| return true
| | | |
| end
| | |岛式 |
| | | |- |
| function p.__eq(lhs, rhs)
| | |白堤路 |
| if #lhs ~= #rhs then
| | | |
| return false
| | |岛式 |
| end
| | |- |
| for i = 1, #lhs do
| | |江川路 |
| if lhs[i] ~= rhs[i] then
| | | |
| return false
| | |岛式 |
| end
| | |- |
| end
| | |杭州路 |
| return true
| | | |
| end
| | |叠侧式 |
| | | | rowspan="1" |江北区 |
| function p.all(enum, fn, clone)
| | |- |
| checkType('Module:Enum.all', 1, enum, 'table')
| | |深圳路 |
| checkType('Module:Enum.all', 2, fn, 'function', true)
| | |<font color="004A9F">█</font> [[星云轨道交通星川线|星川线]] |
| checkType('Module:Enum.all', 3, clone, 'boolean', true)
| | |叠岛式 |
| if clone then enum = mw.clone(enum) end
| | | rowspan="3" |星川区 |
| fn = fn or function(item) return item end
| | |- |
| local i = 1
| | | rowspan="7" |二期 |
| while enum[i] ~= nil do
| | |星川 |
| if not fn(enum[i], i) then
| | |<font color="004A9F">█</font> [[星云轨道交通星川线|星川线]] |
| return false
| | |双岛式 |
| end
| | |- |
| i = i + 1
| | |上海西路 |
| end
| | |<font color="E7CC08">█</font> [[星云轨道交通环线|环线]] |
| return true
| | |岛式 |
| end
| | |- |
| | | |河南路 |
| function p.any(enum, fn, clone)
| | |<font color="17C123">█</font> [[星云轨道交通星岛线|星岛线]] <font color="F79F1F">█</font> [[星云轨道交通空港线|空港线]] |
| checkType('Module:Enum.any', 1, enum, 'table')
| | |岛式 |
| checkType('Module:Enum.any', 2, fn, 'function', true)
| | | rowspan="3" |星轨区 |
| checkType('Module:Enum.any', 3, clone, 'boolean', true)
| | |- |
| if clone then enum = mw.clone(enum) end
| | |星云体育馆 |
| fn = fn or function(item) return item end
| | | |
| local i = 1
| | |侧式 |
| while enum[i] ~= nil do
| | |- |
| if fn(enum[i], i) then
| | |中央公园 |
| return true
| | |<font color="9B59B6">█</font> [[星云轨道交通区域线|区域线]] |
| end
| | |岛式 |
| i = i + 1
| | |- |
| end
| | |东关路 |
| return false
| | |<font color="E7CC08">█</font> [[星云轨道交通环线|环线]] |
| end
| | |岛式 |
| | | | rowspan="2" |星岛区 |
| function p.contains(enum, elem, clone)
| | |- |
| checkType('Module:Enum.contains', 1, enum, 'table')
| | |源深路 |
| checkType('Module:Enum.contains', 3, clone, 'boolean', true)
| | |<font color="45AAF2">█</font> [[星云轨道交通中央线|中央线]] |
| if clone then enum = mw.clone(enum); elem = mw.clone(elem) end
| | |岛式 |
| return p.any(enum, function(item) return item == elem end)
| | |- |
| end
| | |} |
| | |
| function p.each(enum, fn, clone)
| |
| checkType('Module:Enum.each', 1, enum, 'table')
| |
| checkType('Module:Enum.each', 2, fn, 'function')
| |
| checkType('Module:Enum.each', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| fn(enum[i], i)
| |
| i = i + 1
| |
| end
| |
| end
| |
| | |
| function p.filter(enum, fn, clone)
| |
| checkType('Module:Enum.filter', 1, enum, 'table')
| |
| checkType('Module:Enum.filter', 2, fn, 'function', true)
| |
| checkType('Module:Enum.filter', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| fn = fn or function(item) return item end
| |
| local r = setmetatable({}, getmetatable(enum))
| |
| local len = 0
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| if fn(enum[i], i) then
| |
| len = len + 1
| |
| r[len] = enum[i]
| |
| end
| |
| i = i + 1
| |
| end
| |
| return r
| |
| end
| |
| | |
| function p.find(enum, fn, default, clone)
| |
| checkType('Module:Enum.find', 1, enum, 'table')
| |
| checkType('Module:Enum.find', 2, fn, 'function')
| |
| checkType('Module:Enum.find', 4, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum); default = mw.clone(default) end
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| if fn(enum[i], i) then
| |
| return enum[i], i
| |
| end
| |
| i = i + 1
| |
| end
| |
| return default
| |
| end
| |
| | |
| function p.find_index(enum, fn, default, clone)
| |
| checkType('Module:Enum.find_index', 1, enum, 'table')
| |
| checkType('Module:Enum.find_index', 2, fn, 'function')
| |
| checkType('Module:Enum.find_index', 4, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum); default = mw.clone(default) end
| |
| fn = fn or function(item) return item end
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| if fn(enum[i], i) then
| |
| return i
| |
| end
| |
| i = i + 1
| |
| end
| |
| return default
| |
| end
| |
| | |
| function p.newIncrementor(start, step)
| |
| checkType('Module:Enum.newIncrementor', 1, start, 'number', true)
| |
| checkType('Module:Enum.newIncrementor', 2, step, 'number', true)
| |
| step = step or 1
| |
| local n = (start or 1) - step
| |
| local obj = {}
| |
| return setmetatable(obj, {
| |
| __call = function() n = n + step return n end,
| |
| __tostring = function() return n end,
| |
| __index = function() return n end,
| |
| __newindex = function(self, k, v)
| |
| if k == 'step' and type(v) == 'number' then
| |
| step = v
| |
| elseif type(v) == 'number' then
| |
| n = v
| |
| end
| |
| end,
| |
| __concat = function(x, y) return tostring(x) .. tostring(y) end
| |
| })
| |
| end
| |
| | |
| function p.intersect(enum1, enum2, clone)
| |
| checkType('Module:Enum.intersect', 1, enum1, 'table')
| |
| checkType('Module:Enum.intersect', 2, enum2, 'table')
| |
| checkType('Module:Enum.intersect', 3, clone, 'boolean', true)
| |
| if clone then enum1 = mw.clone(enum1); enum2 = mw.clone(enum2) end
| |
| local enum2Elements = {}
| |
| local res = setmetatable({}, getmetatable(enum1) or getmetatable(enum2))
| |
| local len = 0
| |
| p.each(enum2, function(item) enum2Elements[item] = true end)
| |
| p.each(enum1, function(item)
| |
| if enum2Elements[item] then
| |
| len = len + 1
| |
| res[len] = item
| |
| end
| |
| end)
| |
| return res
| |
| end
| |
| | |
| function p.intersects(enum1, enum2, clone)
| |
| checkType('Module:Enum.intersects', 1, enum1, 'table')
| |
| checkType('Module:Enum.intersects', 2, enum2, 'table')
| |
| checkType('Module:Enum.intersects', 3, clone, 'boolean', true)
| |
| if clone then enum1 = mw.clone(enum1); enum2 = mw.clone(enum2) end
| |
| local small = {}
| |
| local large
| |
| if #enum1 <= #enum2 then
| |
| p.each(enum1, function(item) small[item] = true end)
| |
| large = enum2
| |
| else
| |
| p.each(enum2, function(item) small[item] = true end)
| |
| large = enum1
| |
| end
| |
| return p.any(large, function(item) return small[item] end)
| |
| end
| |
| | |
| function p.insert(enum1, enum2, index, clone)
| |
| checkType('Module:Enum.insert', 1, enum1, 'table')
| |
| checkType('Module:Enum.insert', 2, enum2, 'table')
| |
| checkType('Module:Enum.insert', 3, index, 'number', true)
| |
| checkType('Module:Enum.insert', 4, clone, 'boolean', true)
| |
| if clone then enum1 = mw.clone(enum1); enum2 = mw.clone(enum2) end
| |
| local len1 = #enum1
| |
| local len2 = #enum2
| |
| index = index or (len1 + 1)
| |
| local res = setmetatable({}, getmetatable(enum1) or getmetatable(enum2))
| |
| | |
| for i = 1, (len1 + len2) do
| |
| if i < index then
| |
| res[i] = enum1[i]
| |
| elseif i < (index + len2) then
| |
| res[i] = enum2[i - index + 1]
| |
| else
| |
| res[i] = enum1[i - len2]
| |
| end
| |
| end
| |
| | |
| return res
| |
| end
| |
| | |
| function p.map(enum, fn, clone)
| |
| checkType('Module:Enum.map', 1, enum, 'table')
| |
| checkType('Module:Enum.map', 2, fn, 'function')
| |
| checkType('Module:Enum.map', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| local len = 0
| |
| local r = setmetatable({}, getmetatable(enum))
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| local tmp = fn(enum[i], i)
| |
| if tmp ~= nil then
| |
| len = len + 1
| |
| r[len] = tmp
| |
| end
| |
| i = i + 1
| |
| end
| |
| return r
| |
| end
| |
| | |
| function p.max_by(enum, fn, clone)
| |
| checkType('Module:Enum.max_by', 1, enum, 'table')
| |
| checkType('Module:Enum.max_by', 2, fn, 'function')
| |
| checkType('Module:Enum.max_by', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| return unpack(p.reduce(enum, function(new, old)
| |
| local y = fn(new)
| |
| return y > old[2] and {new, y} or old
| |
| end, {enum[1], -math.huge}))
| |
| end
| |
| | |
| function p.new(enum)
| |
| for _, v in pairs(enum) do
| |
| if type(v) == 'table' then
| |
| p.new(v)
| |
| end
| |
| end
| |
| | |
| if getmetatable(enum) == nil then
| |
| setmetatable(enum, p)
| |
| end
| |
| | |
| return enum
| |
| end
| |
| | |
| function p.range(start, stop, step)
| |
| checkType('Module:Enum.range', 1, start, 'number')
| |
| checkType('Module:Enum.range', 2, stop, 'number', true)
| |
| checkType('Module:Enum.range', 3, step, 'number', true)
| |
| local array = setmetatable({}, p)
| |
| local len = 0
| |
| if not stop then
| |
| stop = start
| |
| start = 1
| |
| end
| |
| for i = start, stop, step or 1 do
| |
| len = len + 1
| |
| array[len] = i
| |
| end
| |
| return array
| |
| end
| |
| | |
| function p.reduce(enum, fn, accumulator, clone)
| |
| checkType('Module:Enum.reduce', 1, enum, 'table')
| |
| checkType('Module:Enum.reduce', 2, fn, 'function')
| |
| checkType('Module:Enum.reduce', 4, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum); accumulator = mw.clone(accumulator) end
| |
| local acc = accumulator
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| if i == 1 and not accumulator then
| |
| acc = enum[i]
| |
| else
| |
| acc = fn(enum[i], acc)
| |
| end
| |
| i = i + 1
| |
| end
| |
| return acc
| |
| end
| |
| | |
| function p.reject(enum, fn, clone)
| |
| checkType('Module:Enum.reject', 1, enum, 'table')
| |
| checkTypeMulti('Module:Enum.reject', 2, fn, {'function', 'table', 'nil'})
| |
| checkType('Module:Enum.reject', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| fn = fn or function(item) return item end
| |
| local r = setmetatable({}, getmetatable(enum))
| |
| local len = 0
| |
| if type(fn) == 'function' then
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| if not fn(enum[i], i) then
| |
| len = len + 1
| |
| r[len] = enum[i]
| |
| end
| |
| i = i + 1
| |
| end
| |
| else
| |
| local rejectMap = {}
| |
| p.each(fn, function(item) rejectMap[item] = true end)
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| if not rejectMap[enum[i]] then
| |
| len = len + 1
| |
| r[len] = enum[i]
| |
| end
| |
| i = i + 1
| |
| end
| |
| end
| |
| return r
| |
| end
| |
| | |
| function p.rep(val, n, clone)
| |
| checkType('Module:Enum.rep', 2, n, 'number')
| |
| checkType('Module:Enum.reject', 3, clone, 'boolean', true)
| |
| if clone then val = mw.clone(val) end
| |
| local r = setmetatable({}, p)
| |
| for i = 1, n do
| |
| r[i] = val
| |
| end
| |
| return r
| |
| end
| |
| | |
| function p.scan(enum, fn, accumulator, clone)
| |
| checkType('Module:Enum.scan', 1, enum, 'table')
| |
| checkType('Module:Enum.scan', 2, fn, 'function')
| |
| checkType('Module:Enum.scan', 4, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum); accumulator = mw.clone(accumulator) end
| |
| local acc = accumulator
| |
| local r = setmetatable({}, getmetatable(enum))
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| if i == 1 and not accumulator then
| |
| acc = enum[i]
| |
| else
| |
| acc = fn(enum[i], acc)
| |
| end
| |
| r[i] = acc
| |
| i = i + 1
| |
| end
| |
| return r
| |
| end
| |
| | |
| function p.slice(enum, start, finish, clone)
| |
| checkType('Module:Enum.slice', 1, enum, 'table')
| |
| checkType('Module:Enum.slice', 2, start, 'number', true)
| |
| checkType('Module:Enum.slice', 3, finish, 'number', true)
| |
| checkType('Module:Enum.slice', 4, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| start = start or 1
| |
| finish = finish or #enum
| |
| local r = setmetatable({}, getmetatable(enum))
| |
| local len = 0
| |
| for i = start, finish do
| |
| len = len + 1
| |
| r[len] = enum[i]
| |
| end
| |
| return r
| |
| end
| |
| | |
| function p.split(enum, count, clone)
| |
| checkType('Module:Enum.split', 1, enum, 'table')
| |
| checkType('Module:Enum.split', 2, count, 'number')
| |
| checkType('Module:Enum.split', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| if #enum < count then
| |
| return enum, {}
| |
| elseif count < 1 then
| |
| return {}, enum
| |
| end
| |
| | |
| local x = setmetatable({}, getmetatable(enum))
| |
| local y = setmetatable({}, getmetatable(enum))
| |
| | |
| for i = 1, #enum do
| |
| table.insert(i <= count and x or y, enum[i])
| |
| end
| |
| return x, y
| |
| end
| |
| | |
| function p.sum(enum, clone)
| |
| checkType('Module:Enum.sum', 1, enum, 'table')
| |
| checkType('Module:Enum.sum', 2, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| return p.reduce(enum, function(x, y) return x + y end)
| |
| end
| |
| | |
| function p.take(enum, count, clone)
| |
| checkType('Module:Enum.take', 1, enum, 'table')
| |
| checkType('Module:Enum.take', 2, count, 'number')
| |
| checkType('Module:Enum.take', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| local x, _ = p.split(enum, count)
| |
| return x
| |
| end
| |
| | |
| function p.take_every(enum, n, clone)
| |
| checkType('Module:Enum.take_every', 1, enum, 'table')
| |
| checkType('Module:Enum.take_every', 2, n, 'number')
| |
| checkType('Module:Enum.take_every', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| local r = setmetatable({}, getmetatable(enum))
| |
| local len = 0
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| if (i - 1) % n == 0 then
| |
| len = len + 1
| |
| r[len] = enum[i]
| |
| end
| |
| i = i + 1
| |
| end
| |
| return r
| |
| end
| |
| | |
| function p.unique(enum, fn, clone)
| |
| checkType('Module:Enum.unique', 1, enum, 'table')
| |
| checkType('Module:Enum.unique', 2, fn, 'function', true)
| |
| checkType('Module:Enum.unique', 3, clone, 'boolean', true)
| |
| if clone then enum = mw.clone(enum) end
| |
| fn = fn or function(item) return item end
| |
| local r = setmetatable({}, getmetatable(enum))
| |
| local len = 0
| |
| local hash = {}
| |
| local i = 1
| |
| while enum[i] ~= nil do
| |
| local id = fn(enum[i])
| |
| if not hash[id] then
| |
| len = len + 1
| |
| r[len] = enum[i]
| |
| hash[id] = true
| |
| end
| |
| i = i + 1
| |
| end
| |
| return r
| |
| end
| |
| | |
| function p.zip(enums, clone)
| |
| checkType('Module:Enum.zip', 1, enums, 'table')
| |
| checkType('Module:Enum.zip', 2, clone, 'boolean', true)
| |
| if clone then enums = mw.clone(enums) end
| |
| local r = setmetatable({}, getmetatable(enums))
| |
| local _, longest = p.max_by(enums, function(enum) return #enum end)
| |
| for i = 1, longest do
| |
| local q = {}
| |
| for j = 1, #enums do
| |
| table.insert(q, enums[j][i])
| |
| end
| |
| table.insert(r, q)
| |
| end
| |
| return r
| |
| end
| |
| | |
| return p
| |
| -- </nowiki>
| |