Skip to content
Dennis Corvers edited this page Oct 23, 2026 · 1 revision

Enumerable:count

Returns the number of values in an iterable, optionally counting only values accepted by a predicate.

Syntax

number = values:count(predicate)

Parameters

Parameter Type Description
predicate function(value, sourceKey) (optional) Returns true to include the value in the count.

Returns

An integer count. Without a predicate, counts all values; with a predicate, counts only calls that return exactly true.

Remarks

length, lengthBy, and countBy are aliases. The predicate receives the source iterator key.

Example

local readyCount = LuaQ.from({
    { name = "Ada", ready = true },
    { name = "Bryn", ready = false },
    { name = "Cato", ready = true },
})
    :count(function(player) return player.ready end)
-- 2

See also

Any · All · Functions

Clone this wiki locally