Skip to content

Comparison Operators

Comparison operators in Filtrera are used to compare values and return boolean results based on the comparison. Filtrera supports six comparison operators: ==, !=, <, >, <=, and >=. This reference guide provides a detailed specification of these comparison operators, their syntax, and usage for users already familiar with the concept.

Available Operators

The comparison operators in Filtrera are:

  • ==: Equal to
  • !=: Not equal to
  • <: Less than
  • >: Greater than
  • <=: Less than or equal to
  • >=: Greater than or equal to

== Operator

The == operator checks if two values are equal. It returns true if the values are equal, and false otherwise.

Syntax

<expression1> == <expression2>

Example

let a = 5
let b = 5
let result = a == b
from result

In this example, result is true because a is equal to b.

!= Operator

The != operator checks if two values are not equal. It returns true if the values are not equal, and false otherwise.

Syntax

<expression1> != <expression2>

Example

let a = 5
let b = 10
let result = a != b
from result

In this example, result is true because a is not equal to b.

< Operator

The < operator checks if the value on the left is less than the value on the right. It returns true if the left value is less, and false otherwise.

Syntax

<expression1> < <expression2>

Example

let a = 5
let b = 10
let result = a < b
from result

In this example, result is true because a is less than b.

> Operator

The > operator checks if the value on the left is greater than the value on the right. It returns true if the left value is greater, and false otherwise.

Syntax

<expression1> > <expression2>

Example

let a = 10
let b = 5
let result = a > b
from result

In this example, result is true because a is greater than b.

<= Operator

The <= operator checks if the value on the left is less than or equal to the value on the right. It returns true if the left value is less than or equal, and false otherwise.

Syntax

<expression1> <= <expression2>

Example

let a = 5
let b = 5
let result = a <= b
from result

In this example, result is true because a is less than or equal to b.

>= Operator

The >= operator checks if the value on the left is greater than or equal to the value on the right. It returns true if the left value is greater than or equal, and false otherwise.

Syntax

<expression1> >= <expression2>

Example

let a = 10
let b = 5
let result = a >= b
from result

In this example, result is true because a is greater than or equal to b.

Practical Usage

Example: Using Comparison Operators in Conditional Logic

param age: number
let category = age match
when age < 13 |> 'Child'
when age >= 13 and age < 20 |> 'Teen'
when age >= 20 and age < 65 |> 'Adult'
when age >= 65 |> 'Senior'
from category

In this example, age is categorized based on its value using comparison operators and pattern matching with the when keyword.

Example: Complex Comparisons

let a = 10
let b = 20
let c = 15
let isAEqualB = a == b
let isCLessThanB = c < b
let isAGreaterOrEqualC = a >= c
from isAEqualB
from isCLessThanB
from isAGreaterOrEqualC

In this example, multiple comparisons are performed, and the results are returned.

Summary

Comparison operators in Filtrera provide the tools necessary to compare values and determine relationships between them. The ==, !=, <, >, <=, and >= operators allow you to construct precise logical expressions and control the flow of your logic based on value comparisons. By understanding and leveraging these operators, you can create robust and flexible Filtrera programs that handle a wide range of comparison operations with ease.