Skip to content

bmel:filter

Category: Array & Statistics · Returns: bmel:array

Signature
bmel:filter(array: bmel:array, predicate: bmel:expression)

Description

Returns the elements of bmel:array for which bmel:predicate is true, in their original order. Within bmel:predicate the current element is accessible as the special reference bmel:item and its zero-based position as bmel:i; read a field of the element with bmel:item.<path>. Use it to keep only the rows that matter as the row source of a NESTED_TABLE — e.g. only the elements of one kind: bmel:filter({op:Response Payload}.$.items, bmel:item.kind == '<kind>'). Returns an empty array for an empty or null bmel:array.

Arguments

Parameter Type Required Description
array bmel:array The array to filter — a payload array, or the N occurrences of a value of a MANY operation.
predicate bmel:expression Boolean expression evaluated for each element; the element is kept when it is true. The current element is accessible as bmel:item and its zero-based position as bmel:i.

Examples

Only the items of one category
bmel:filter({getOrder:Response Payload}.$.items, bmel:item.category == 'electronics')
Only the LLM calls slower than one second
bmel:filter({createChatCompletion:Response Payload[]}.$.latency_ms, bmel:item > 1000)
Total of the discounted items
bmel:sum(bmel:map(bmel:filter({getOrder:Response Payload}.$.items, bmel:item.discount > 0), bmel:item.price))

← Back to BMEL Reference