single
Full name: taxi.stdlib.single
Signature
declare extension function <T> single(collection:T[], callback: (T) -> Boolean):TDescription
Returns the first item from a collection that matches the provided predicate. Throws an error if no matching item is found.
This function is useful when you need to find a specific element in a collection based on a condition.
// Find a product by its SKU code
find { inventory: Inventory } as {
appleMacbook: inventory.products.single((product) -> product.sku == "MB-PRO-2023")
}Examples
Finds the single product matching the given SKU. Throws if no match or more than one match is found.
Try it out
Schema
Query Plan
Play with this snippet by editing it here, or edit it on Taxi Playground
Result
Query failed