Anonymous

Module:FunList/Sandbox: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local Enumerable = require('Module:Enumerable')
-- This is required to allow chaining if Enumerable functions in a FP manner.
local EnumerableExtensions = require('Module:EnumerableExtensions')
local TableEnumerator = require('Module:TableEnumerator')


local Debug = require('module:Debug')
---A wrapper for a Lua Table type that turns it into an Enumerable. Allows iteration over the table contents via a state-machine.
local FL = require('module:FunList/Enumerators')
---@class TableIterator : Enumerable
---@field _tbl table
local TableIterator = setmetatable({}, { __index = Enumerable })
TableIterator.__index = TableIterator
TableIterator.__pairs  = Enumerable.getPairs
TableIterator.__ipairs = Enumerable.getiPairs


function p.test()
function TableIterator.new(tbl)
local tbl = {}
    local self = setmetatable(Enumerable.new(), TableIterator)
    -- Allow creation of empty enumerable
    self._tbl = tbl or {}
    return self
end
 
function TableIterator:getEnumerator(isArray)
return TableEnumerator.create(self._tbl, isArray)
end
 
-- Collection of shortcut functions so we don't have to iterate over all of the data
-- in case the target enumerable is a TableIterator.
function TableIterator:getCount()
    return #self._tbl
end


for i = 1, 10 do
function TableIterator:getLast()
    tbl[i] = string.char(string.byte('a') + i - 1) -- Calculate the character
    return self._tbl[#self._tbl]
end
end
tbl['TextOK'] = 999
local enum = FL.TableEnumerator.new(tbl)


local concatEnum = FL.ConcatEnumerator.new(enum, {1,2,3,4,5,6})
function TableIterator:getTable()
local selectEnum = FL.MapEnumerator.new(concatEnum, function(x) return x .. x end)
    return self._tbl
for k, v in pairs(selectEnum) do
Debug.log(v)
end
--Debug.log(enum)
end
end


return p
return TableIterator
2,875

edits