Value
The value
data type in Filtrera is a virtual type that represents a union of all types, excluding functions and nothing
. This reference guide provides a detailed specification of the value
data type, its syntax, and usage for users already familiar with the concept.
The value
type is designed to be a flexible and inclusive type that can hold any valid Filtrera data type except for functions and nothing
. It is similar to a union type but differs in that it implicitly includes all types, rather than explicitly stating its subtypes. If anything, it can be considered as an intersection of two negated types: not function
and not nothing
.
Type Notation for value
The type notation for value
is simply value
. There is no literal value for the value
type, as it is compatible with any non-function and non-nothing type.
Example
let anyValue: value
In this example, anyValue
is a variable that can hold any type of value except for functions and nothing
.
Usage
The value
type can be used in situations where you want to accept or return any type of value without explicitly defining a union of specific types. This makes it useful for generic programming and functions that need to handle a variety of data types.
Example: Accepting Any Value
let printValue = (v: value) => $'Value: {v}'
let result1 = printValue(123)let result2 = printValue('Hello')let result3 = printValue([1, 2, 3])
from result1from result2from result3
In this example, printValue
is a function that accepts any value and returns a string representation of that value. The function can handle numbers, text, iterators, and other compatible types.
Practical Usage
Example: Handling Different Data Types
let processValue = (v: value) => from v match (x: text) |> $'Text: {x}' (x: number) |> $'Number: {x}' (x: [number]) |> $'Iterator of Numbers: {x}' (x: value) |> $'Other Type: {x}'
let result1 = processValue('Hello')let result2 = processValue(42)let result3 = processValue([1, 2, 3])let result4 = processValue(true)
from result1from result2from result3from result4
In this example, processValue
processes different types of values and returns a corresponding string. The function can handle text, numbers, iterators of numbers, and other compatible types. Note that x: value
is used to match any type that is not explicitly stated, ensuring it does not include nothing
or functions.
Summary
The value
data type in Filtrera provides a flexible and inclusive way to handle any type of value except for functions and nothing
. By understanding its syntax and usage, including type notation and practical examples, you can leverage the value
type to create generic and versatile programs. The value
type simplifies handling various data types and enhances the flexibility and robustness of your Filtrera programs.