Implement the 'add' builtin promised by the docs' examples.

This commit is contained in:
Stephen Dolan committed 2012-09-18 23:32:24 +01:00
1 parent fbf7bc835b
commit 5863160112
3 files changed
+61

No files matched your search

+37
View File
@@ -321,6 +321,43 @@ sections:
input: '[[1,2], "string", {"a":2}, null]'
output: [2, 6, 1, 0]
- title: `map(x)`
body: |
For any filter `x`, `map(x)` will run that filter for each
element of the input array, and produce the outputs a new
array. `map(.+1)` will increment each element of an array of numbers.
`map(x)` is equivalent to `[.[] | x]`. In fact, this is how
it's defined.
examples:
- program: 'map(.+1)'
input: '[1,2,3]'
output: ['[2,3,4]']
- title: `add`
body: |
The filter `add` takes as input an array, and produces as
output the elements of the array added together. This might
mean summed, concatenated or merged depending on the types
of the elements of the input array - the rules are the same
as those for the `+` operator (described above).
If the input is an empty array, `add` returns `null`.
examples:
- program: add
input: '["a","b","c"]'
output: ["abc"]
- program: add
input: '[1, 2, 3]'
output: [6]
- program: add
input: '[]'
output: ["null"]
- title: `tonumber`
body: |