]> granicus.if.org Git - jq/commitdiff
Add index and rindex builtins
authorNicolas Williams <nico@cryptonector.com>
Mon, 2 Dec 2013 18:19:23 +0000 (12:19 -0600)
committerNicolas Williams <nico@cryptonector.com>
Thu, 5 Dec 2013 00:21:42 +0000 (18:21 -0600)
builtin.c

index aa3c888a2001fa849305d7d9a1aab6d09b3e293e..087741faacdfc4712377be67489cd7597383fe77 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -676,6 +676,8 @@ static const char* const jq_builtins[] = {
   "def from_entries: map({(.key): .value}) | add;",
   "def with_entries(f): to_entries | map(f) | from_entries;",
   "def reverse: [.[length - 1 - range(0;length)]];",
+  "def index(i): .[i][0];",
+  "def rindex(i): .[i][-1:][0];",
 };