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] = {
item = offer.item,
profit = profit,
tradesLastHour = offer.tradesLastHour,
}
end
end
table.sort(candidates, function(a, b) return a.profit > b.profit end)
for i = #candidates, 6, -1 do candidates[i] = nil end
local bestFlips = candidatesLuaQ expresses the same filter, projection, 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)
:map(function(offer)
return {
item = offer.item,
profit = offer.sellPrice - offer.buyPrice,
tradesLastHour = offer.tradesLastHour,
}
end)
:toTable()Both versions return the same compact records, ordered by gross profit. The
LuaQ query replaces the explicit candidate-building loop, sort, and trimming
with a short chain of where, sortByDescending, take, and map. It maps
only the five results. Margins here are before any fees.
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