Keyword: is
The is keyword in Filtrera is used as an operator to match a value against a type pattern and returns a boolean indicating whether the value matches the type pattern. This reference guide provides a detailed specification of the is keyword, focusing on its syntax and usage.
The is keyword is an operator that allows you to check if a value matches a specified type pattern. It returns true if the value matches the type pattern and false otherwise. This operator is useful for performing type checks and conditional logic based on the type of a value.
Syntax
Basic Syntax
<value> is <type><value>: The value to be checked against the type pattern.<type>: The type pattern to match the value against.
Example
let value = 42let isNumber = value is number
from isNumberIn this example, isNumber will be true because value is a number.
Detailed Syntax
Checking Simple Types
You can use the is keyword to check if a value matches a simple type such as text, number, or boolean.
let value = 'Hello'let isText = value is text
from isTextIn this example, isText will be true because value is a text.
Checking Complex Types
You can also use the is keyword to check if a value matches a complex type such as records or tuples.
let person = { name = 'Alice', age = 30 }let isPerson = person is { name: text, age: number }
from isPersonIn this example, isPerson will be true because person matches the record type with name as text and age as number.
Using Negated Types
The is keyword can be combined with negated types to check if a value does not match a specific type or value.
let value = 'Hello'let isNonEmptyText = value is (text & not '')
from isNonEmptyTextIn this example, isNonEmptyText will be true because value is a non-empty text.