content/flux/v0/stdlib/universe/bool.md
bool() converts a value to a boolean type.
(v: A) => bool
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
({{< req >}}) Value to convert.
bool(v: "true")
// Returns true
bool(v: "false")// Returns false
bool(v: 1.0)
// Returns true
bool(v: 0.0)
// Returns false
bool(v: 1)
// Returns true
bool(v: 0)
// Returns false
bool(v: uint(v: 1))
// Returns true
bool(v: uint(v: 0))// Returns false
If converting the _value column to boolean types, use toBool().
If converting columns other than _value, use map() to iterate over each
row and bool() to convert a column value to a boolean type.
data
|> map(fn: (r) => ({r with powerOn: bool(v: r.powerOn)}))
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| _time | powerOn | *tag |
|---|---|---|
| 2021-01-01T00:00:00Z | 1 | t1 |
| 2021-01-01T00:00:10Z | 1 | t1 |
| 2021-01-01T00:00:20Z | 0 | t1 |
| 2021-01-01T00:00:30Z | 1 | t1 |
| 2021-01-01T00:00:40Z | 0 | t1 |
| 2021-01-01T00:00:50Z | 0 | t1 |
| _time | powerOn | *tag |
|---|---|---|
| 2021-01-01T00:00:00Z | 0 | t2 |
| 2021-01-01T00:00:10Z | 1 | t2 |
| 2021-01-01T00:00:20Z | 0 | t2 |
| 2021-01-01T00:00:30Z | 1 | t2 |
| 2021-01-01T00:00:40Z | 1 | t2 |
| 2021-01-01T00:00:50Z | 0 | t2 |
| _time | powerOn | *tag |
|---|---|---|
| 2021-01-01T00:00:00Z | true | t1 |
| 2021-01-01T00:00:10Z | true | t1 |
| 2021-01-01T00:00:20Z | false | t1 |
| 2021-01-01T00:00:30Z | true | t1 |
| 2021-01-01T00:00:40Z | false | t1 |
| 2021-01-01T00:00:50Z | false | t1 |
| _time | powerOn | *tag |
|---|---|---|
| 2021-01-01T00:00:00Z | false | t2 |
| 2021-01-01T00:00:10Z | true | t2 |
| 2021-01-01T00:00:20Z | false | t2 |
| 2021-01-01T00:00:30Z | true | t2 |
| 2021-01-01T00:00:40Z | true | t2 |
| 2021-01-01T00:00:50Z | false | t2 |
{{% /expand %}} {{< /expand-wrapper >}}