Anonymous

Module:FunList/Sandbox: Difference between revisions

From Melvor Idle
no edit summary
(Created page with "local p = {} local Debug = require('module:Debug') local FL = require('module:FunList') function p.test() local tbl = { { name = "Alice", age = 30, gender = "female" }, { name = "Bob", age = 25, gender = "male" }, { name = "Charlie", age = 35, gender = "male" }, { name = "David", age = 28, gender = "male" }, { name = "Eve", age = 32, gender = "female" }, { name = "Frank", age = 27, gender = "male" }, { name = "Grace", age = 31, gender = "fe...")
 
No edit summary
Line 2: Line 2:


local Debug = require('module:Debug')
local Debug = require('module:Debug')
local FL = require('module:FunList')
local FL = require('module:FunList/Enumerators')


function p.test()
function p.test()
local tbl = {
local tbl = {}
    { name = "Alice", age = 30, gender = "female" },
 
    { name = "Bob", age = 25, gender = "male" },
for i = 1, 10 do
    { name = "Charlie", age = 35, gender = "male" },
    tbl[i] = string.char(string.byte('a') + i - 1)  -- Calculate the character
    { name = "David", age = 28, gender = "male" },
end
    { name = "Eve", age = 32, gender = "female" },
tbl['TextOK'] = 999
    { name = "Frank", age = 27, gender = "male" },
    { name = "Grace", age = 31, gender = "female" },
local enum = FL.TableEnumerator.new(tbl)
    { name = "Harry", age = 26, gender = "male" },
local enum2 = FL.TableEnumerator.new({1,2,3,4,5,6})
    { name = "Ivy", age = 29, gender = "female" },
    { name = "Jack", age = 32, gender = "male" }
local concatEnum = FL.ConcatEnumerator.new(enum, enum2)
}
local selectEnum = FL.SelectEnumerator.new(concatEnum, function(x) return x .. x end)
local fl = FL.new(tbl)
for k, v in ipairs(selectEnum) do
 
Debug.log(v)
local result = fl:sortBy(function(x) return x.gender end)
end
:thenBy(function(x) return x.name end)
--Debug.log(enum)
:sort()
:toTable()
 
Debug.log(result)
end
end


return p
return p
2,875

edits