Skip to content
Dennis Corvers edited this page Oct 23, 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] = {
            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 = candidates

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

Source

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

Clone this wiki locally