Repository navigation
Home
LuaQ is a reusable Lua library for working with iterables through a fluent
Enumerable API. It provides chainable filtering, projection, set operations,
sorting, grouping, queries, and collection conversions.
-
Getting Started — load LuaQ, create an
Enumerable, and run the tests. - Functions — reference pages for operators, queries, iteration, and conversion.
Suppose a price tracker has an offers list with each item's current
buyPrice, sellPrice, and tradesLastHour. To show the five most promising
liquid flips, require at least 10 trades per hour and a gross margin of at
least 5,000 GP. In plain Lua, build the candidates, sort them, and trim the
list:
local candidates = {}
for _, offer in ipairs(offers) do
local profit = offer.sellPrice - offer.buyPrice
if offer.buyPrice > 0 and offer.tradesLastHour >= 10 and profit >= 5000 then
candidates[#candidates + 1] = offer
end
end
table.sort(candidates, function(a, b)
return a.sellPrice - a.buyPrice > b.sellPrice - b.buyPrice
end)
for i = #candidates, 6, -1 do candidates[i] = nil end
local bestFlips = candidatesLuaQ expresses the same filter, ordering, and limit as a single query:
local bestFlips = LuaQ.from(offers)
:where(function(offer) return offer.buyPrice > 0
and offer.tradesLastHour >= 10
and offer.sellPrice - offer.buyPrice >= 5000 end)
:sortByDescending(function(offer) return offer.sellPrice - offer.buyPrice end)
:take(5)
:toTable()Both versions return the original offer records for the five highest gross
margins. The LuaQ query replaces the explicit filtering loop, sort, and list
trimming with where, sortByDescending, and take.
The library source is src/enumerable.lua.
The test suite is in tests.
- Home
- Getting Started
-
Functions
- aggregate
- all
- any
- concat
- contains
- count
- create
- createFrom
- deepCopy
- difference
- elementAt
- elementAtOrDefault
- first
- firstOrDefault
- flatMap
- foreach
- groupBy
- groupByResult
- indexOf
- intersect
- ipairs
- last
- lastOrDefault
- map
- max
- min
- pairs
- sequenceEquals
- single
- singleOrDefault
- sort
- sortBy
- sortByDescending
- sortDescending
- sum
- take
- takeWhile
- thenBy
- thenByDecending
- toLookup
- toMap
- toSet
- toTable
- union
- unique
- where
- zip
- Aliases