You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/spec.adoc
+8-11Lines changed: 8 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,6 @@ If the supplied data is not correct for the execution context, json-formula will
76
76
* The left-hand operand of ordering comparison operators (`>`, `>=`, `<`, `\<=`) must be a string or number. Any other type shall be coerced to a number.
77
77
* If the operands of an ordering comparison are different, they shall both be coerced to a number
78
78
* Parameters to functions shall be coerced when there is a single viable coercion available. For example, if a null value is provided to a function that accepts a number or string, then coercion shall not happen, since a null value can be coerced to both types. Conversely if a string is provided to a function that accepts a number or array of numbers, then the string shall be coerced to a number, since there is no supported coercion to convert it to an array of numbers.
79
-
* When functions accept a typed array, the function rules determine whether coercion may occur. Some functions (e.g. `avg()`) ignore array members of the wrong type. Other functions (e.g. `abs()`) coerce array members. If coercion may occur, then any provided array will have each of its members coerced to the expected type. e.g., if the input array is `[2,3,"6"]` and an array of numbers is expected, the array will be coerced to `[2,3,6]`.
80
79
81
80
The equality and inequality operators (`=`, `==`, `!=`, `<>`) do **not** perform type coercion. If operands are different types, the values are considered not equal.
82
81
@@ -94,7 +93,7 @@ In all cases except ordering comparison, if the coercion is not possible, a `Typ
94
93
eval([1,2,3] ~ 4, {}) -> [1,2,3,4]
95
94
eval(123 < "124", {}) -> true
96
95
eval("23" > 111, {}) -> false
97
-
eval(avg(["2", "3", "4"]), {}) -> 3
96
+
eval(avgA(["2", "3", "4"]), {}) -> 3
98
97
eval(1 == "1", {}) -> false
99
98
----
100
99
@@ -130,7 +129,7 @@ In all cases except ordering comparison, if the coercion is not possible, a `Typ
130
129
| null | boolean | false
131
130
|===
132
131
133
-
An array may be coerced to another type of array as long as there is a supported coercion for the array content. For examples, just as a string can be coerced to a number, an array of strings may be coerced to an array of numbers.
132
+
An array may be coerced to another type of array as long as there is a supported coercion for the array content. For example, just as a string can be coerced to a number, an array of strings may be coerced to an array of numbers.
134
133
135
134
Note that while strings, numbers and booleans may be coerced to arrays, they may not be coerced to a different type within that array. For example, a number cannot be coerced to an array of strings -- even though a number can be coerced to a string, and a string can be coerced to an array of strings.
136
135
@@ -142,7 +141,7 @@ Note that while strings, numbers and booleans may be coerced to arrays, they may
142
141
eval("\"$123.00\" + 1", {}) -> TypeError
143
142
eval("truth is " & `true`, {}) -> "truth is true"
144
143
eval(2 + `true`, {}) -> 3
145
-
eval(avg(["20", "30"]), {}) -> 25
144
+
eval(minA(["20", "30"]), {}) -> 20
146
145
----
147
146
148
147
=== Date and Time Values
@@ -1204,8 +1203,7 @@ output.
1204
1203
1205
1204
=== Function parameters
1206
1205
1207
-
Functions support the set of standard json-formula <<Data Types, data types>>. If the resolved arguments cannot be coerced to
1208
-
match the types specified in the signature, a `TypeError` error occurs.
1206
+
Functions support the set of standard json-formula <<Data Types, data types>>. If the parameters cannot be coerced to match the types specified in the signature, a `TypeError` error occurs.
1209
1207
1210
1208
As a shorthand, the type `any` is used to indicate that the function argument can be
1211
1209
any of (`array|object|number|string|boolean|null`).
@@ -1229,14 +1227,12 @@ does not exist, a `FunctionError` error is raised.
1229
1227
Many functions that process scalar values also allow for the processing of arrays of values. For example, the `round()` function may be called to process a single value: `round(1.2345, 2)` or to process an array of values: `round([1.2345, 2.3456], 2)`. The first call will return a single value, the second call will return an array of values.
1230
1228
When processing arrays of values, and where there is more than one parameter, each parameter is converted to an array so that the function processes each value in the set of arrays. From our example above, the call to `round([1.2345, 2.3456], 2)` would be processed as if it were `round([1.2345, 2.3456], [2, 2])`, and the result would be the same as: `[round(1.2345, 2), round(2.3456, 2)]`.
1231
1229
1232
-
Functions that accept array parameters will also accept nested arrays. With nested arrays, aggregating functions (min(), max(), avg(), sum() etc.) will flatten the arrays. e.g.
1233
-
1234
-
`avg([2.1, 3.1, [4.1, 5.1]])` will be processed as `avg([2.1, 3.1, 4.1, 5.1])` and return `3.6`.
1230
+
Functions that accept array parameters will also accept nested arrays. Aggregating functions (`min()`, `max()`, `avg()`, `sum()`, etc.) will flatten nested arrays. e.g. `avg([2.1, 3.1, [4.1, 5.1]])` will be processed as `avg([2.1, 3.1, 4.1, 5.1])` and return `3.6`.
1235
1231
1236
1232
Non-aggregating functions will return the same array hierarchy. e.g.
1237
1233
1238
-
`upper("a", ["b"]]) => ["A", ["B"]]`
1239
-
`round([2.12, 3.12, [4.12, 5.12]], 1)` will be processed as `round([2.12, 3.12, [4.12, 5.12]], [1, 1, [1, 1]])` and return `[2.1, 3.1, [4.1, 5.1]]`
1234
+
`upper(["a", ["b"]]) => ["A", ["B"]]`
1235
+
`round([2.12, 3.12, [4.12, 5.12]], 1)` will be processed as `round([2.12, 3.12, [4.12, 5.12]], [1, 1, [1, 1]])` and return `[2.1, 3.1, [4.1, 5.1]]`
1240
1236
1241
1237
These array balancing rules apply when any parameter is an array:
1242
1238
@@ -1246,6 +1242,7 @@ These array balancing rules apply when any parameter is an array:
1246
1242
* The function will return an array which is the result of iterating over the elements of the arrays and applying the function logic on the values at the same index.
1247
1243
1248
1244
With nested arrays:
1245
+
1249
1246
* Nested arrays will be flattened for aggregating functions
1250
1247
* Non-aggregating functions will preserve the array hierarchy and will apply the balancing rules to each element of the nested arrays
0 commit comments