Skip to content
Dennis Corvers edited this page Nov 13, 2026 · 8 revisions

LuaQ

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.

Documentation

  • Getting Started — load LuaQ, create an Enumerable, and run the tests.
  • Functions — reference pages for operators, queries, iteration, and conversion.

Example: finding promising flips

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 = candidates

LuaQ 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.

Source

The library source is src/enumerable.lua. The test suite is in tests.

Clone this wiki locally