Appendix 2: AMDL Operators

This section details the full list of operators within AMDL and their usage.

Operator Precedence

In the table below, all AMDL operators are listed in precedence order from highest to lowest. Operators in the same row of the table have the same precedence. Each operator is left, right, or non-associative as follows:

  • Left-associative operators of the same precedence bind to the left: e1 op e2 op e3 becomes (e1 op e2) op e3.

  • Right-associative operators of the same precedence bind to the right: e1 op e2 op e3 becomes e1 op (e2 op e3).

  • Non-associative operators do not appear in contexts where their binding is ambiguous.

Operator

Associativity

.

( )

left

[ ]

none

!

~

right

*

/

left

+

-

. .

~:

left

>

> =

<

< =

left

==

!=

left

Collection operators

right

&&

left

||

left

~?

right

??

right

? :

right

The following sections on operators describe what the above operators mean.

Mathematical Operators

Operators: + - * /

As well as operating on numbers, + and - can also operate on times and durations. You can add or subtract durations, and add or subtract a duration to a time.

Example

Effect

1 + 2

Basic addition. This evaluates to 3.

event.amount - 50

Returns the value of the amount field in the event minus 50.

event.amount.baseValue * state.storedValue

Returns the baseValue field multiplied by some stored value.

event.count /event.numberOfItems

Returns a count divided by a number.

String Concatenation Operator

Operator: ..

This operator concatenates any two strings, numbers, durations, or times as strings. For non-strings this is done in such a format that they can be coerced back to their original types.

Example

Effect

"Hello " .. "World"

Evaluates to "Hello World".

event.firstName .. " " .. event.lastName

Produces a full name from component parts.

Comparison and Equality Operators

These return a boolean value indicating the result of the comparison. Note that the first two operators can be applied to strings as well as numbers, durations, and times. However, the latter four cannot be used for strings.

Operator

Description

Example

Effect

==

equals

1 == 1

"foo" == "bar"

This is always true.

You can also check for equality amongst strings. The above is always false.

!=

does not equal

event.phoneNumber != "999"

Checking an event field is not equal to "999".

<

less than

500 < event.amount.baseValue

Checking an event field is more than a parameter value.

<=

or equal

event.amount.baseValue <=param.thresholdValue

Checking an event field does not exceed a parameter value.

>

greater than

500 > event.amount.baseValue

Checking an event field is less than a parameter value.

>=

greater than or equal

500 >= event.amount.baseValue

Checking an event field is equal to or less than a parameter value.

Event fields can appear either side of the comparison operator.

Boolean Operators

These operators are used upon Boolean values.

Operator

Description

Example

Effect

&&

AND

event.isFruit && event.isGreen

This is only true if both fields are true.

||

OR

state.isFruit || var.isGreen

This is only false if both variables are false.

!

NOT

!true

This is always false.

Collection Membership Operators

These operators are used to test membership of a collection, and return a Boolean value. In usage, the left-hand operand must always be some form of collection, and the right-hand operand the element of the collection whose membership is being tested.

Operator

Description

Example

Effect

~#

contains

event.transactionAmounts ~# 20
values.declineStatusCodes ~# event.responseMessage

Checking that a list in the event contains the value 20.00.

Checking whether a string in the event is contained within a pre-defined collection of values.

!#

does not contain

{ "GB", "US", "IS" } !# event.country

Checking that the country field in the event is not one of "GB", "US" or "IS".

Collection Comparison Operators

These operators perform comparison operations upon all elements of a collection and return the Boolean combination of the results. The left operand must always be a collection and the right operand that which is to be compared.

Operator

Description

Example

Effect

==#

All equal to value

[ 1, 1, 1, 1, 1 ] ==# 1

All elements of the ordered collection are equal to 1, so this is true.

!=#

None equal to value

{ "apple", "pear", "banana" } !=# "strawberry"

None of the elements in the collection are equal to "strawberry", so this is true.

<#

All less than value

event.transactionAmounts <# values.threshold

Check that all values are less than to some pre-defined threshold.

<=#

All less than or equal to value

event.transactionAmounts <=# values.threshold

Check that all values are less than or equal to some pre-defined threshold.

>#

All greater than value

event.transactionAmounts ># event.accountOpenDateTime

Check that all values are greater than to some pre-defined datetime.

>=#

All greater than or equal to value

event.transactionAmounts >=# values.threshold

Check that all values are greater than or equal to some pre-defined threshold.

Ternary Operator

This operator allows one of two operations to be evaluated based upon a boolean condition. The operator is a useful control flow tool to use if, for instance, there are special cases that need treatment.

Operator

Description

Example

Effect

? :

Evaluate value x if boolean is true, else evaluate value y

Copy
event.eventType == "registration" ?
event.eventTime : event.regTime

If the event type is "registration", this evaluates to the value of event.eventTime. However, if not, it evaluates to the event.regTime.

?

 

Copy
event.eventType == "registration" ?
event.eventTime

The 'else' part of the ternary operation is optional. If the Boolean condition evaluates to false, expression evaluation stops.

Switch Case Operator

This operator allows one of many operations to be evaluated based upon a switch expression. This is useful if you have several special cases for the same variable, each of which needs different treatment.

Operator

Description

Example

Effect

~?

Evaluate multiple operations

Copy
event.mcc ~? "7995": event.amount.baseValue > 150;
"5912": event.amount.baseValue > 200;
"4722": event.amount.baseValue > 5000;
default: event.amount.baseValue > 500;

Check the event amount against a different threshold based on the mcc field.

 

 

Copy
event.mcc ~? "7995": event.amount.baseValue > 150;
"5912": event.amount.baseValue > 200;
"4722": event.amount.baseValue > 5000;

The 'default' case is optional. In this case, if the expression does not evaluate to one of the case labels, the expression evaluation stops.

Case labels must be a fixed value or a 'default'. Currently, switching based upon variable expressions is not supported. Also note that every switch case must be terminated by a semicolon.

'Default Value' Operator

In AMDL, expression evaluation stops if a referenced variable does not exist. The ?? operator allows a default value to be specified if an expression cannot be evaluated.

Operator

Description

Example

Effect

??

This operator is used if the field does not exist (because data has not been populated). The operator is also used if the field contains null values.

Copy
( event.amount.baseValue ?? 0 ) > 100

If the event does not contain a field called amount.baseValue, this evaluates to 0 instead. This is particularly useful when dealing with optional fields that may or may not be present in the event.

You can default to the value of another field or a state or other variable as well as a fixed value.

??

This operator is used if the field does not exist (because data has not been populated). The operator is also used if the field contains null values.

Copy
( event.chargebackTime ?? event.eventTime ) <
                            state.prevTime + 90d

You can default to the value of another field or a state or other variable as well as a fixed value.

'Exists' Operator

This operator checks whether evaluation of a reference returns a non-null value.

Operator

Description

Example

Effect

~

Field Exists

Copy
~event.optionalField

Evaluates to true if the optionalField is present in the event being processed.

 

 

Copy
~state.previousTransactionValue

Evaluates to true if the previousTransactionValue is defined in the state of the entity being processed.

Regular Expression Matches Operator

This operator checks whether the left string operand matches the regular expression contained in the right operand.

This operator can only be applied to strings. For more information on regular expressions, see Outputting Values.

Operator

Description

Example

Effect

~=

Field matches regular expression

Copy
event.address.postcode ~= "/^CB/"

Checks whether the postcode starts with "CB".

Regular Expression Substitution Operator

This operator performs a substitution specified in the right operand on the left string operand.

This operator can only be applied to strings. For more information on regular expressions, see Outputting Values.

Operator

Description

Example

Effect

~:

Substitute values in operand

Copy
"1970.01.01" ~: "/-/./"

Substitutes dots with dashes, resulting in "1970-01-01".

Regexes can be quoted or unquoted.