From 0b5da6e8505a47fae984e7445b800b864164c6f1 Mon Sep 17 00:00:00 2001 From: David Fetter Date: Mon, 29 Oct 2018 07:12:50 -0700 Subject: [PATCH] Make reverse more DWIM-y Strings now work. Other types' current behavior preserved. --- src/builtin.jq | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builtin.jq b/src/builtin.jq index 92209237ac..2db9ba4493 100644 --- a/src/builtin.jq +++ b/src/builtin.jq @@ -23,7 +23,7 @@ def recurse_down: recurse; def to_entries: [keys_unsorted[] as $k | {key: $k, value: .[$k]}]; def from_entries: map({(.key // .Key // .name // .Name): (if has("value") then .value else .Value end)}) | add | .//={}; def with_entries(f): to_entries | map(f) | from_entries; -def reverse: [.[length - 1 - range(0;length)]]; +def reverse: def r: [.[length - 1 - range(0;length)]]; if type == "string" then explode | r | implode else r end; def indices($i): if type == "array" and ($i|type) == "array" then .[$i] elif type == "array" then .[[$i]] elif type == "string" and ($i|type) == "string" then _strindices($i)