Enumerable Where - FireDragon91245/Lua-Linq GitHub Wiki

enumerable:where

Filters items and returns only the entries that match. It supports direct predicates, string expressions, pattern tables, and selector/value comparisons.

Overloads

enumerable<T>   :where(predicate: fun(item: T): boolean):           enumerable<T>
enumerable<K, V>:where(predicate: fun(key: K, value: V): boolean):  enumerable<K, V>

enumerable<T>   :where(predicate: string):                          enumerable<T>
enumerable<K, V>:where(predicate: string):                          enumerable<K, V>

enumerable<T>   :where(pattern: table):                             enumerable<T>
enumerable<K, V>:where(pattern: table):                             enumerable<K, V>

enumerable<T>   :where(pattern: table, comparer: equality_comparer): enumerable<T>
enumerable<K, V>:where(pattern: table, comparer: equality_comparer): enumerable<K, V>

enumerable<T>   :where(
    selector: fun(item: T): R,
    value:    R
): enumerable<T>
enumerable<K, V>:where(
    selector: fun(key: K, value: V): R,
    value:    R
): enumerable<K, V>

enumerable<T>   :where(
    selector: fun(item: T): R,
    value:    R,
    comparer: equality_comparer
): enumerable<T>
enumerable<K, V>:where(
    selector: fun(key: K, value: V): R,
    value:    R,
    comparer: equality_comparer
): enumerable<K, V>

enumerable<T>   :where(selector: string, value: any):               enumerable<T>
enumerable<K, V>:where(selector: string, value: any):               enumerable<K, V>

enumerable<T>   :where(
    selector: string,
    value:    any,
    comparer: equality_comparer
): enumerable<T>
enumerable<K, V>:where(
    selector: string,
    value:    any,
    comparer: equality_comparer
): enumerable<K, V>
  • predicate: string acts as a key/property selector when it does not contain =>. If it contains => it is treated as a lambda expression.
  • selector: string follows the same rule for the selector/value overloads.

Examples

local evens = linq.list(1, 2, 3, 4):where("n => n % 2 == 0"):spread()
local heavy = linq.list({ name = "iron", count = 4 }, { name = "copper", count = 12 })
    :where("count", 12)
    :first()
⚠️ **GitHub.com Fallback** ⚠️