Skip to content
Dennis Corvers edited this page Oct 23, 2026 · 2 revisions

Enumerable:where

Filters an Enumerable to include only values accepted by a predicate. where is deferred: the predicate runs when the returned Enumerable is iterated.

Syntax

filtered = source:where(predicate)

Parameters

Parameter Type Description
predicate function(value, position) Returns true to keep the value. Position is 1-based.

Returns

A new Enumerable containing values for which the predicate returns true.

Remarks

The predicate must return the boolean true to retain a value. It receives the value and its 1-based position in the source sequence.

Example

local availableFood = LuaQ.from({
    { item = "Shark", quantity = 12 },
    { item = "Saradomin brew", quantity = 0 },
    { item = "Manta ray", quantity = 6 },
})
    :where(function(stack) return stack.quantity > 0 end)
    :toTable()
-- Keeps the Shark and Manta ray stacks

See also

Map · Take · TakeWhile · Functions

Clone this wiki locally