Skip to main content

Boolean Logic

The following set of functions all evaluate to true or false. They provide an alternate notation to using operators that may lend itself better when writing declarative code (e.g. when defining the fields of a declaration).

equals

Syntax

equals?($left or @left, $right or @right)

Description

This function checks whether both arguments are equals, it is equivalent to doing left == right.

Arguments

PositionPossible ValuesRequiredDefault Value
1Resource collection -OR- ValueYesNone
2Resource collection -OR- ValueYesNone

Result

true or false.

Examples

$a = 1 
$b = 2
$c = 1
equals?($a, $b) == false
equals?($a, $c) == true

switch

Syntax

switch($condition, @true_exp or $true_exp, @false_exp or $false_exp)

Description

This function evaluates the condition and returns either the true expression or false expression based on the value of $condition.

Arguments

PositionPossible ValuesRequiredDefault Value
1ValueYesNone
2Resource collection -OR- ValueYesNone
3Resource collection -OR- ValueYesNone
note

Both true expression and false expression should be of the same type.

Result

true expression or false expression

Examples

$anything_but_null = "foobar" 
$false_or_null = null
switch($anything_but_null, $var1, $var2) == $var1
switch($false_or_null, @ec2, @google) == @google

logic_and and logic_or

Syntax

logic_and($left, $right) and logic_or($left, $right)

Description

These functions apply the logical and or logical or operators respectively to their arguments. They are equivalent to $left && $right and $left || $right respectively.

Arguments

PositionPossible ValuesRequiredDefault Value
1ValueYesNone
2ValueYesNone

Result

true or false.

Examples

$anything_but_null = "foobar" 
$false_or_null = null
switch($anything_but_null, $var1, $var2) == $var1
switch($false_or_null, @ec2, @google) == @google

logic_not

Syntax

logic_not($value​)

Description

Applies the logical not operator.

Arguments

PositionPossible ValuesRequiredDefault Value
1ValueYesNone

Result

true or false.

Examples

logic_not(true) == false 
logic_not(false) == true
$any_value_but_null = "foobar"
logic_not($any_value_but_null) == false
logic_not(null) == true