Debian Codegraph @

docs/conversion.md

raw
1 # Type Conversion Functions
2
3 The following type conversion functions are provided by Sprig:
4
5 - `atoi`: Convert a string to an integer.
6 - `float64`: Convert to a `float64`.
7 - `int`: Convert to an `int` at the system's width.
8 - `int64`: Convert to an `int64`.
9 - `toDecimal`: Convert a unix octal to a `int64`.
10 - `toString`: Convert to a string.
11 - `toStrings`: Convert a list, slice, or array to a list of strings.
12
13 Only `atoi` requires that the input be a specific type. The others will attempt
14 to convert from any type to the destination type. For example, `int64` can convert
15 floats to ints, and it can also convert strings to ints.
16
17 ## toStrings
18
19 Given a list-like collection, produce a slice of strings.
20
21 ```
22 list 1 2 3 | toStrings
23 ```
24
25 The above converts `1` to `"1"`, `2` to `"2"`, and so on, and then returns
26 them as a list.
27
28 ## toDecimal
29
30 Given a unix octal permission, produce a decimal.
31
32 ```
33 "0777" | toDecimal
34 ```
35
36 The above converts `0777` to `511` and returns the value as an int64.