[[condition-function-reference]]
== Function reference


The condition syntax supports the following functions.

[[add-function]]
=== `add`
`add(Number, Number) Number`

Usage:

[source,eql]
----
add(1, 2) == 3
add(5, ${foo}) >= 5
----

[[arrayContains-function]]
=== `arrayContains`

`arrayContains(Array, String) Boolean`

Usage:

[source,eql]
----
arrayContains(${docker.labels}, 'monitor')
----

[[concat-function]]
=== `concat`

`concat(String, String) String`

NOTE: Parameters are coerced into strings before the concatenation.

Usage:

[source,eql]
----
concat("foo", "bar") == "foobar"
concat(${var1}, ${var2}) != "foobar"
----

[[divide-function]]
=== `divide`

`divide(Number, Number) Number`

Usage:

[source,eql]
----
divide(25, 5) > 0
divide(${var1}, ${var2}) > 7
----

[[endsWith-function]]
=== `endsWith`

`endsWith(String, String) Boolean`


Usage:

[source,eql]
----
endsWith("hello world", "hello") == true
endsWith(${var1}, "hello") != true
----

[[hasKey-function]]
=== `hasKey`

`hasKey(Dictionary, String) Boolean`

Usage:

[source,eql]
----
hasKey(${host}, "platform")
----

[[indexOf-function]]
=== `indexOf`

`indexOf(String, String, Number?) Number`

NOTE: Returns -1 if the string is not found.

Usage:

[source,eql]
----
indexOf("hello", "llo") == 2
indexOf(${var1}, "hello") >= 0
----

[[length-function]]
=== `length`

`length(Array|Dictionary|string)`

Usage:

[source,eql]
----
length("foobar") > 2
length(${docker.labels}) > 0
length(${host}) > 2
----

[[match-function]]
=== `match`

`match(String, Regexp) boolean`

NOTE: `Regexp` supports Go's regular expression syntax. Conditions that use
regular expressions are more expensive to run. If speed is critical, consider
using `endWiths` or `startsWith`.

Usage:

[source,eql]
----
match("hello world", "^hello") == true
match(${var1}, "world$") == true
----

[[modulo-function]]
=== `modulo`

`modulo(number, number) Number`

Usage:

[source,eql]
----
modulo(25, 5) > 0
modulo(${var1}, ${var2}) == 0
----

[[multiply-function]]
=== `multiply`

`multiply(Number, Number) Number`

Usage:

[source,eql]
----
multiply(5, 5) == 25
multiple(${var1}, ${var2}) > x
----

[[number-function]]
=== `number`

`number(String) Integer`

Usage:

[source,eql]
----
number("42") == 42
number(${var1}) == 42
----

[[startsWith-function]]
=== `startsWith`

`startsWith(String, String) Boolean`

Usage:

[source,eql]
----
startsWith("hello world", "hello") == true
startsWith(${var1}, "hello") != true
----

[[string-function]]
=== `string`

`string(Number) String`

Usage:

[source,eql]
----
string(42) == "42"
string(${var1}) == "42"
----

[[stringContains-function]]
=== `stringContains`

`stringContains(String, String) Boolean`

Usage:

[source,eql]
----
stringContains("hello world", "hello") == true
stringContains(${var1}, "hello") != true
----

[[subtract-function]]
=== `subtract`

`subtract(Number, Number) Number`

Usage:

[source,eql]
----
substract(5, 1) == 4
subtract(${foo}, 2) != 2
----
