# Operators Reference

## Special Operators

### = (equality)

**infix**

`(T?, T) => boolean`

Tests for equality, e.g. `5 = 4`

yields `false`

while `"s" = "s"`

yields `true`

.

For types `tuple`

and `array`

, the comparison is performed element-wise.

Syntax bug! Due to a bug, the type of the second operand must be assignment compatible to the type of the first operand.

I.e., doing`5.3 = 5`

is valid but`5 = 5.3`

raises a syntax error. This will be fixed in the future.

### != (inequality)

**infix**

`(T?, T) => boolean`

Performs the negated operation of = (equality).

Syntax bug! This operator currently suffers from the same bug as

`= (equality)`

.

### if-then-else (ternary)

**special**

`(boolean, T?, T) => T`

Evaluates the condition (first operand) and if it is `true`

returns the second operand, otherwise returns the third operand.

#### Examples

Syntax bug! This operator currently suffers from the same bug as

`= (equality)`

.

### asset

**function**

`(text) => text`

Returns the address of a game asset by using the asset resolver component.

For example, calling `asset("star.png")`

might return something like `"https://game-server.org/game-assets/MySpaceGame/star.png"`

.

Check the assets documentation to find out more.

## Text Operators

### + (concat text)

**infix**

`(text, text) => text`

Performs text (string) concatenation, e.g. `"alpha" + "bet"`

yields `"alphabet"`

.

### toText (integer)

**function**

`(int) => text`

Converts an integer to text, e.g. `toText(5)`

yields `"5"`

.

### toText (real)

**function**

`(real) => text`

Converts a real to text, e.g. `toText(5.3)`

yields `"5.3"`

.

### toText (boolean)

**function**

`(boolean) => text`

Converts a boolean to text, e.g. `toText(false)`

yields `"false"`

.

## Sequence Operators

### exists

**prefix**

`(seq[?]) => boolean`

### first

**prefix**

`(seq[E?]) => E`

Returns the first element of the sequence or `nothing`

if the sequence is empty.

### second

**prefix**

`(seq[E?]) => E`

Returns the second element of the sequence or `nothing`

if the sequence has fewer than two elements.

### third

**prefix**

`(seq[E?]) => E`

Returns the third element of the sequence or `nothing`

if the sequence has fewer than three elements.

### in

**infix**

`(E, seq[E?]) => boolean`

Returns true iff the element is contained in the sequence.

The elements are compared using the equality operator.

#### Examples

### collect

**prefix**

`(seq[E?]) => array[E]`

Collects the elements of the sequence into an array.

This is particularly useful for either stabilizing the results of a query or optimizing the performance of lazy operations.

#### Examples

### + (concat sequence)

**infix**

`(seq[E?], seq[E]) => seq[E]`

### >> (append)

**infix**

`(seq[E?], E) => seq[E]`

### << (prepend)

**infix**

`(E, seq[E?]) => seq[E]`

### .. | range

**infix | function**

`(int, int) => seq[int]`

Returns an integer range from the first operand to the second operand (inclusive).

This operator has two alternative equivalent syntaxes:

- The
`..`

, eg,`1..3`

- The function
`range`

, eg,`range(1, 3)`

#### Examples

### cross

**infix**

`(seq[X?], seq[Y?]) => seq[(X, Y)]`

### map

**infix**

`(seq[S?], (S) => T?) => seq[T]`

Applies the function to the elements of the input sequence and produces the output sequence.

#### Examples

### find

**infix**

`(seq[E?], (E) => boolean) => E`

Returns the first element for which the function returns `true`

or `nothing`

if there is no such element.

#### Examples

### reduce

**infix**

`(seq[E?], Acc, (Acc?, E) => Acc) => Acc`

## Logical Operators

## Arithmetic Operators

### // (integer division)

**infix**

`(int, int) => int`

Performs integer division on two integers.

### / (real)

**infix**

`(real, real) => real`

Divides two reals.

Note: If this operator is used on integers, they will be converted to real. E.g.

`5 / 2`

will yield`2.5`

.

### mathFloor

**function**

`(real) => int`

Returns the floor of a real, e.g. `mathFloor(2.5)`

yields `2`

.

### mathCeil

**function**

`(real) => int`

Returns the ceil of a real, e.g. `mathFloor(2.5)`

yields `3`

.

### mathSgn (integer)

**function**

`(int) => int`

Returns the sign of an int number, that is:

- if number < 0: return -1
- if number = 0: return 0
- if number > 0: return 1

### mathSgn (real)

**function**

`(real) => int`

Returns the sign of a real number, that is:

- if number < 0: return -1
- if number = 0: return 0
- if number > 0: return 1