You should adopt the JavaScript approach and make dictionaries a separate thing. In JavaScript you have three “table-like” classes: Object, Array, and Map (Set not included*) They’re done this way because some methods may only apply nicely to arrays and not dictionaries/maps. They seemingly are the same while also being vastly different at the same time. It is worth noting a Map should be able to be converted into an Array and keep its data.
Object is the closest relative to Lua tables, but iterator functions have to pretty much be pre-defined and they always feel inferior to use over the other two.
One more thing I wanted to address was sending ql objects through remote events.
Just use ql.get_table() as the argument, and remake the QuickList after in the connection.
Client (LocalScript)
local RemoteEvent = game.ReplicatedStorage.RE
local _ = require('QuickList')
local myTable = {"Hello", "World"}
RemoteEvent:FireServer(myTable.get_table()) -- Convert QuickList into a table
Server (Script)
local RemoteEvent = game.ReplicatedStorage.RE
local _ = require('QuickList')
RemoteEvent.OnServerEvent:Connect(function(player, myTable)
local QL_myTable = _(myTable) -- Convert the table into a quicklist
print(QL_myTable)
end)
Roblox (lua) tables are pretty lacking, and also each table method has to be called using the original table class, rather than calling it directly.
Quicklist solves this issue by just wrapping the table in a metatable and adding a bunch of extra built-in features on top of that. Python’s datatypes let you call their methods directly using dot notation, and hence the same for quicklist. Also I was inspired a little by javascript for some things too.
Take for example, the random, sum and average methods. These aren’t in the table class, and it just helps to have them all in one place and to be able to call them directly. A bunch of QuickList’s methods return a copy of the list, which is also useful.
local my_list: ql.Quicklist = ql {
1, 2, 3, 4
}
my_list.retain(function(i: number, v: any)
if v % 2 == 0 then
return true
end
end)
print(my_list) -- Will print `{2, 4}` since it retained any even number.