Skip to content

Commit

Permalink
Make reverse more DWIM-y
Browse files Browse the repository at this point in the history
Strings now work. Other types' current behavior preserved.
  • Loading branch information
davidfetter committed Jan 2, 2019
1 parent 0bc7708 commit 0b5da6e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/builtin.jq
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0b5da6e

Please sign in to comment.