Skip to content

Intersect

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

Enumerable:intersect

Returns unique values from the source whose selected keys are also found in a second iterable.

Syntax

common = source:intersect(second, keySelector)

Parameters

Parameter Type Description
second iterable Values to compare against.
keySelector function(value, sourceKey) (optional) Selects comparison keys for both inputs.

Returns

A deferred Enumerable containing matching source values, at most once per key, in source iteration order.

Remarks

Without a selector, values themselves are used as keys. With a selector, the same selector is applied to both inputs. Selected keys must not be nil.

Example

local party = LuaQ.from({
    { id = 41, name = "Ada" },
    { id = 58, name = "Bryn" },
    { id = 73, name = "Cato" },
})
    :intersect({
        { id = 58, name = "Bryn" },
        { id = 73, name = "Cato" },
    }, function(player) return player.id end)
    :toTable()
-- Only players also present in the second roster

See also

Unique · Difference · Union · Functions

Clone this wiki locally