Skip to main content

$first

$first(array, function) -> value
Compact type signature<af>

Source: FUME

Availability​

Community v3.0.0+
Enterprise v3.0.0+

Documentation​

Returns the first element whose predicate result is truthy under JSONata boolean rules.

The callback receives the current value, index, and source array. If the first argument is not already an array, FUME treats it as a one-item sequence. If no item matches, or the input is undefined, $first() returns undefined instead of throwing.

Examples​

Find the first matching line​

Input

This example uses the claims-lines example input. The expression returns the first line that meets the threshold.

Example input

JSON
[
{
"claimId": "clm-2001",
"lineNumber": 1,
"serviceCode": "PROC-010",
"serviceDisplay": "office visit",
"units": 1,
"unitPrice": 125,
"allowedAmount": 110,
"modifiers": [
"MOD-A"
]
},
{
"claimId": "clm-2001",
"lineNumber": 2,
"serviceCode": "PROC-020",
"serviceDisplay": "imaging study",
"units": "1",
"unitPrice": 350,
"allowedAmount": 300,
"modifiers": [
"MOD-B",
"MOD-C"
]
},
{
"claimId": "clm-2001",
"lineNumber": 3,
"serviceCode": "PROC-030",
"serviceDisplay": "lab panel",
"units": 2,
"unitPrice": 40,
"allowedAmount": 70,
"modifiers": []
},
{
"claimId": "clm-2002",
"lineNumber": 1,
"serviceCode": "PROC-010",
"serviceDisplay": "office visit",
"units": 1,
"unitPrice": 125,
"allowedAmount": 115,
"modifiers": [
"MOD-A"
]
},
{
"claimId": "clm-2002",
"lineNumber": 2,
"serviceCode": "PROC-040",
"serviceDisplay": "counseling",
"units": 3,
"unitPrice": 60,
"allowedAmount": 150,
"modifiers": [
"MOD-D"
]
}
]

Expression

$first($, function($l) { $l.allowedAmount >= 150 }).lineNumber

Result

2