Other Operators
& (Concatenation)
The string concatenation operator is used to join the string values of the operands into a single resultant string. If either or both of the operands are not strings, then they are first cast to string using the rules of the $string function.
Example
Input
This example uses the full claim-batch example input. The next two examples read fields from that document to demonstrate concatenation and conditional evaluation.
Example input
{
"claimId": "clm-9001",
"memberId": "mbr-3001",
"claimLines": [
{
"lineNumber": 1,
"serviceDisplay": "office visit",
"allowedAmount": 110,
"modifiers": [
"MOD-A"
],
"units": 1,
"unitPrice": 125
},
{
"lineNumber": 2,
"serviceDisplay": "imaging study",
"allowedAmount": 300,
"modifiers": [
"MOD-B",
"MOD-C"
],
"units": 1,
"unitPrice": 350
},
{
"lineNumber": 3,
"serviceDisplay": "counseling",
"allowedAmount": 150,
"modifiers": [],
"units": 3,
"unitPrice": 60
},
{
"lineNumber": 4,
"serviceDisplay": "lab panel",
"allowedAmount": 70,
"modifiers": [
"MOD-A"
],
"units": 2,
"unitPrice": 40
}
]
}
Expression:
claimId & "-L" & claimLines[1].lineNumber
Result:
"clm-9001-L2"
? : (Conditional)
The conditional ternary operator is used to evaluate one of two alternative expressions based on the result of a predicate (test) condition. The operator takes the form:
<test_expr> ? <expr_T> : <expr_F>
The <test_expr> expression is first evaluated. If it evaluates to Boolean true, then the operator returns the result of evaluating the <expr_T> expression. Otherwise it returns the result of evaluating the <expr_F> expression. If <test_expr> evaluates to a non-Boolean value, then the value is first cast to Boolean using the rules of the $boolean function.
Example
This example continues to use the claim-batch input shown above. The expression evaluates the fourth claim line's allowedAmount from the full document.
Expression:
claimLines[3].allowedAmount < 100 ? "low" : "standard"
Result:
"low"
?: (Default/Elvis)
The default, or Elvis, operator returns the left-hand side when it has an effective Boolean value of true. Otherwise, it returns the right-hand side. The operator takes the form:
<expr1> ?: <expr2>
Use this operator when an expression should fall back not only when a value is missing, but also when the value is present and evaluates to Boolean false, such as null, false, 0, "", an empty array, an empty object, or undefined. FUME uses the same Boolean conversion rules as $boolean() to decide whether the left-hand side is truthy.
The ?: operator is available in FUME Community and FUME Enterprise from v3.x onwards.
Example
This example continues to use the claim-batch input shown above. The first expression returns the modifier from the first claim line. The second expression falls back because the third claim line has an empty modifiers array.
Expression:
claimLines[0].modifiers[0] ?: "NO-MODIFIER"
Result:
"MOD-A"
Expression:
claimLines[2].modifiers[0] ?: "NO-MODIFIER"
Result:
"NO-MODIFIER"
?? (Coalescing)
The coalesce operator returns the left-hand side when it is defined. If the left-hand side does not evaluate to a defined value, the operator returns the right-hand side. The operator takes the form:
<expr1> ?? <expr2>
Use this operator when a fallback should apply only to a missing value. Unlike ?:, the coalesce operator keeps defined values that have an effective Boolean value of false, such as false, 0, "", null, an empty array, or an empty object.
The ?? operator is available in FUME Community and FUME Enterprise from v3.x onwards.
Example
This example continues to use the claim-batch input shown above. The first expression keeps a defined numeric value, even though 0 evaluates to Boolean false. The second expression falls back because missingAmount is not present on the claim line.
Expression:
(claimLines[0].allowedAmount - 110) ?? 999
Result:
0
Expression:
claimLines[0].missingAmount ?? 999
Result:
999
Choosing between ?: and ??
Use ?: when the fallback should cover any value that behaves as false in a condition. Use ?? when the fallback should cover only missing or undefined values while preserving defined values such as null, false, and "".
Array constructor
Square brackets can be used to construct a new array. This is the normal JSON syntax for arrays, and it works in FUME expressions because JSON literals are valid expression syntax.
Use an array constructor when you want to return a fixed-size list of values. Array items can be any valid expression, and the output array will contain the evaluation results of the corresponding expressions, in the same order.
Note: Array items that evaluate to undefined are omitted from the result array.
Example: Build a new array from expressions
Input
{
"claimId": "clm-9001",
"lineCount": 2,
"allowed": [110, 180]
}
Expression
[claimId, lineCount, allowed[0]]
Result
[
"clm-9001",
2,
110
]
Async note
Array construction is a basic language feature, but also a concurrency helper. Parallel execution of array expression is possible when the entries contain async expressions.
For example, [$wait(1000), $wait(1000), $wait(1000)] finishes in about one second rather than three because the three waits can start together. See Parallelism And Async Evaluation for the full model, and browse related helpers in Async And Concurrency.
Object constructor
Curly braces can be used to construct a new object. Each entry is written as key: value. Keys may be string literals (quoted) or expressions that evaluate to strings. Values may be any expression.
Object constructors can be used either to build one object per selected item or to group a sequence into one combined object, depending on where the constructor appears in the expression.
Example: Build one object per input item
Input
{
"contacts": [
{ "kind": "home", "value": "555-0101" },
{ "kind": "work", "value": "555-0201" },
{ "kind": "work", "value": "555-0202" }
]
}
Expression
contacts.{kind: value}
Result
[
{ "home": "555-0101" },
{ "work": "555-0201" },
{ "work": "555-0202" }
]
Because the constructor follows the dot-map stage, each contact builds its own object.
Example: Group many items into one object
Input
{
"contacts": [
{ "kind": "home", "value": "555-0101" },
{ "kind": "work", "value": "555-0201" },
{ "kind": "work", "value": "555-0202" }
]
}
Expression
contacts{kind: value}
Result
{
"home": "555-0101",
"work": ["555-0201", "555-0202"]
}
Because the constructor follows the whole selected sequence directly, FUME combines the generated key/value pairs into one object. Repeated keys are grouped into arrays. This grouped form is also the basis of the reduce-style { ... } stage documented in Path Operators.
JSON literals
Any valid JSON document is also a valid FUME expression. That means you can write strings, numbers, booleans, null, arrays, and objects directly in an expression, then replace selected parts with dynamic expressions.
This makes JSON syntax useful as a template for the output you want to build.
Example: Use JSON syntax as an output template
Input
{
"claimId": "clm-9001",
"allowedAmount": 180
}
Expression
{
"id": claimId,
"allowedAmount": allowedAmount,
"status": "ready",
"highAllowedAmount": allowedAmount >= 150,
"notes": null
}
Result
{
"id": "clm-9001",
"allowedAmount": 180,
"status": "ready",
"highAllowedAmount": true,
"notes": null
}
:= (Variable binding)
The variable binding operator is used to bind the value of the RHS to the variable name defined on the LHS. The variable binding is scoped to the current block and any nested blocks. It is an error if the LHS is not a $ followed by a valid variable name.
Examples
$five := 5$square := function($n) { $n * $n }
~> (Chain)
The function chaining operator is used in the situations where multiple nested functions need to be applied to a value, while making it easy to read. The value on the LHS is evaluated, then passed into the function on the RHS as its first argument. If the function has any other arguments, then these are passed to the function in parenthesis as usual. It is an error if the RHS is not a function, or an expression that evaluates to a function.
Examples
Input
This example uses the full claim-batch example input. The next two chain examples read either claimId or claimLines from that document before passing the value into chained functions.
Example input
{
"claimId": "clm-9001",
"memberId": "mbr-3001",
"claimLines": [
{
"lineNumber": 1,
"serviceDisplay": "office visit",
"allowedAmount": 110,
"modifiers": [
"MOD-A"
],
"units": 1,
"unitPrice": 125
},
{
"lineNumber": 2,
"serviceDisplay": "imaging study",
"allowedAmount": 300,
"modifiers": [
"MOD-B",
"MOD-C"
],
"units": 1,
"unitPrice": 350
},
{
"lineNumber": 3,
"serviceDisplay": "counseling",
"allowedAmount": 150,
"modifiers": [],
"units": 3,
"unitPrice": 60
},
{
"lineNumber": 4,
"serviceDisplay": "lab panel",
"allowedAmount": 70,
"modifiers": [
"MOD-A"
],
"units": 2,
"unitPrice": 40
}
]
}
Expression:
claimId ~> $substringAfter("clm-") ~> $number()
Result:
9001
This example continues to use the claim-batch input shown above. The expression calculates each claim line total from the full document and then sums the resulting sequence.
Expression:
claimLines.(unitPrice * $number(units)) ~> $sum()
Result:
735
This operator can also be used in a more abstract form to define new functions based on a combination of existing functions. In this form, there is no value passed in on the LHS of the first function in the chain.
For example, the expression
(
$uppertrim := $trim ~> $uppercase;
$uppertrim(" Hello World ")
)
Result:
"HELLO WORLD"
creates a new function $uppertrim that performs $trim followed by $uppercase.