indices() and range() functions #49
Replies: 2 comments 4 replies
-
I so like PowerShell syntax, although you cannot select a 1..100 |% { Write-Host $_ } To generate the range from |
Beta Was this translation helpful? Give feedback.
-
The range() and indices() Functions
AbstractThis JEP proposes a set of functions to produce an array of numbers, most commonly used for iteration a given number of times. Specificationindices
The If By extension, if NotesAn object in JMESPath is defined as an unordered collection of key-value pairs. For this reason, the Examples
range
The The If the If the If not specified, the More formally, the
Examples
Compliance TestsA new History
|
Beta Was this translation helpful? Give feedback.
-
It can be quite useful to generate an array of sequential numbers, especially when wanting to use them in subsequent logic as array indexes.
The function to do this would follow the python equivalent of
array[number] range(number start[, number stop[, number step]])
.Input vs Actual values used
examples:
search("foo", let({root: @}, map(&[@, root[@]], range(length(@))))
->[[0, "f"],[1, "o"],[2, "o"]]
search("", range(-10))
->[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
search("", range(0))
->[]
additionally the pattern
range(length(@))
will likely occur so often that it would be advantageous to allowrange(@)
to be equivalent if@
is a type with length (array|object|string).Beta Was this translation helpful? Give feedback.
All reactions