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

Enumerable:union

Returns unique values from the source and a second iterable.

Syntax

combined = source:union(second, keySelector)

Parameters

Parameter Type Description
second iterable Additional values to include.
keySelector function(value, sourceKey) (optional) Selects keys used to remove duplicates.

Returns

A deferred Enumerable containing the first value for each key, enumerating the source before the second iterable.

Remarks

Without a selector, each value is used as its key. With a selector, the same selector is used for both inputs. Selected keys must not be nil.

Example

local party = LuaQ.from({
    { id = 41, name = "Ada" },
    { id = 58, name = "Bryn" },
})
    :union({
        { id = 58, name = "Bryn (duplicate)" },
        { id = 73, name = "Cato" },
    }, function(player) return player.id end)
    :toTable()
-- Keeps one entry per player id

See also

Unique · Difference · Intersect · Functions

Clone this wiki locally