Skip to content

FlatMap

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

Enumerable:flatMap

Projects each source value to an iterable and flattens the projected iterables into one Enumerable. flatMap is deferred.

Syntax

flattened = source:flatMap(selector)

Parameters

Parameter Type Description
selector function(value, position) Returns a table iterable for the source value. Position is 1-based.

Returns

A new Enumerable containing the values of each selected iterable in source order.

Remarks

selectMany is an alias of flatMap. Each selector result must be a table supported by LuaQ's iterator setup.

Example

local drops = LuaQ.from({
    { npc = "Abyssal demon", items = { "Abyssal whip", "Coins" } },
    { npc = "Gargoyle", items = { "Granite maul", "Coins" } },
})
    :flatMap(function(dropTable) return dropTable.items end)
    :toTable()
-- { "Abyssal whip", "Coins", "Granite maul", "Coins" }

See also

Map · Concat · Functions

Clone this wiki locally