commit
9d5ac359d9
|
|
@ -13,6 +13,7 @@ Flux includes the following types of operators:
|
|||
|
||||
- [Arithmetic operators](#arithmetic-operators)
|
||||
- [Comparison operators](#comparison-operators)
|
||||
- [Logical operators](#logical-operators)
|
||||
- [Assignment operators](#assignment-operators)
|
||||
- [Function operators](#function-operators)
|
||||
- [String Operators](#string-operators)
|
||||
|
|
@ -24,7 +25,7 @@ Arithmetic operators take two numerical values (either literals or variables) an
|
|||
perform a calculation that returns a single numerical value.
|
||||
|
||||
| Operator | Description | Example | Result |
|
||||
|:--------:| ----------- | ------- | ------ |
|
||||
|:--------:|:----------- | ------- | ------ |
|
||||
| `+` | Addition | `1 + 1` | `2` |
|
||||
| `-` | Subtraction | `3 - 2` | `1` |
|
||||
| `*` | Multiplication | `2 * 3` | `6` |
|
||||
|
|
@ -41,7 +42,7 @@ Operations with values of different numeric types will result in a type error.
|
|||
Comparison operators compare expressions and return true or false based on the comparison.
|
||||
|
||||
| Operator | Description | Example | Result |
|
||||
|:--------:| ----------- | ------- | ------ |
|
||||
|:--------:|:----------- | ------- | ------ |
|
||||
| `==` | Equal to | `"abc" == "abc"` | `true` |
|
||||
| `!=` | Not equal to | `"abc" != "def"` | `true` |
|
||||
| `<` | Less than | `1 < 2` | `true` |
|
||||
|
|
@ -55,11 +56,26 @@ Comparison operators compare expressions and return true or false based on the c
|
|||
The `>` and `<` operators also [compare the lexicographic order of strings](#string-operators).
|
||||
{{% /note %}}
|
||||
|
||||
## Logical operators
|
||||
| Operator | Description |
|
||||
|:--------:|:----------- |
|
||||
| `and` | Returns `true` if both operands are true. Otherwise, returns `false`. |
|
||||
| `or` | Returns `true` if any operand is true. Otherwise, returns `false`. |
|
||||
|
||||
#### Short-circuit evaluation
|
||||
Flux logical operators observe the short-circuiting behavior seen in other programming languages.
|
||||
The evaluation of the left-hand (LH) operand determines if the right-hand (RH) operand is evaluated.
|
||||
|
||||
- When the operator is `and` and the LH operand evaluates to `false`, the evaluation
|
||||
returns `false` without evaluating the RH operand.
|
||||
- When the operator is `or` and the LH operand evaluates to `true`, the evaluation
|
||||
returns `true` without evaluating the RH operand.
|
||||
|
||||
## Assignment operators
|
||||
An assignment operator assigns a value to its left operand based on the value of its right operand.
|
||||
|
||||
| Operator | Description | Example | Meaning |
|
||||
|:--------:| ----------- | ------- | ------- |
|
||||
|:--------:|:----------- | ------- | ------- |
|
||||
| `=` | Assign value of left expression to right expression | `x = y` | x = y |
|
||||
|
||||
|
||||
|
|
@ -67,7 +83,7 @@ An assignment operator assigns a value to its left operand based on the value of
|
|||
Function operators facilitate the creation of functions and control the flow of data through operations.
|
||||
|
||||
| Operator | Description | Examples | Meaning |
|
||||
|:--------: | ----------- | -------- | ------- |
|
||||
|:--------: |:----------- | -------- | ------- |
|
||||
| <code>|></code> | Pipe‑forward | <code>data |> function()</code> | Tables contained in the "data" variable are piped into the function. |
|
||||
| `<-` | Pipe‑receive | `tables=<-` | The "tables" variable or parameter is assigned to data piped into the operation. _This operator is used for any data type passed into a function; not just table data._ |
|
||||
| `=>` | Arrow | `(r) => r.tag1 == "tagvalue"` | The arrow passes an object or parameters into function operations. |
|
||||
|
|
@ -83,7 +99,7 @@ _See [Custom functions](/v2.0/query-data/guides/custom-functions) for examples o
|
|||
String operators concatenate or compare string values.
|
||||
|
||||
| Operator | Description | Examples | Result |
|
||||
|:--------:| ----------- | -------- | ------ |
|
||||
|:--------:|:----------- | -------- | ------ |
|
||||
| `+` | Concatenation | `"ab" + "c"` | `"abc"` |
|
||||
| `<` | Less than in lexicographic order | `"ant" < "bee"` | `true` |
|
||||
| `>` | Greater than in lexicographic order | `"ant" > "bee"` | `false` |
|
||||
|
|
@ -99,7 +115,7 @@ Literal constructors define fixed values.
|
|||
|
||||
## Miscellaneous operators
|
||||
| Operator | Description | Example |
|
||||
|:--------:| ----------- | ------- |
|
||||
|:--------:|:----------- | ------- |
|
||||
| `( )` | Logical grouping | `r._value / (r._value * 2)` |
|
||||
| `,` | Sequence delimiter | `item1, item2, item3` |
|
||||
| `:` | Key-value separator | `{name: "Bob"}` |
|
||||
|
|
|
|||
Loading…
Reference in New Issue