Skip to content

Logical Operators

Logical operators in Filtrera are used to perform logical operations on boolean expressions. Filtrera supports three logical operators: and, or, and not. This reference guide provides a detailed specification of these logical operators, their syntax, and usage for users already familiar with the concept.

Available Operators

The logical operators in Filtrera are:

  • and: Logical AND
  • or: Logical OR
  • not: Logical NOT

and Operator

The and operator evaluates to true if both operands are true, and false otherwise.

Syntax

<expression1> and <expression2>

Example

let a = true
let b = false
let result = a and b
from result

In this example, result is false because a and b evaluates to false.

or Operator

The or operator evaluates to true if at least one of the operands is true, and false if both operands are false.

Syntax

<expression1> or <expression2>

Example

let a = true
let b = false
let result = a or b
from result

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

not Operator

The not operator inverts the value of its operand. It evaluates to true if the operand is false, and false if the operand is true.

Syntax

not <expression>

Example

let a = true
let result = not a
from result

In this example, result is false because not a evaluates to false.

Practical Usage

Example: Combining Logical Operators

let a = true
let b = false
let c = true
let combined = (a and b) or (not c)
from combined

In this example, combined is evaluated using a combination of and, or, and not operators. The result is false because (a and b) is false and (not c) is also false.

Example: Conditional Logic with Pattern Matching

param isActive: boolean
param isVerified: boolean
let status = (isActive and isVerified) match
true |> 'User is active and verified.'
false |> 'User is not fully verified.'
from status

In this example, status is determined using a combination of and and pattern matching based on the values of isActive and isVerified.

Summary

Logical operators in Filtrera provide the tools necessary to perform boolean logic within your programs. The and, or, and not operators allow you to construct complex logical expressions and control the flow of your logic based on boolean conditions. By understanding and leveraging these operators, you can create robust and flexible Filtrera programs that handle a wide range of logical operations with ease.