summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Lapresta <santiago.lapresta@gmail.com>2014-05-21 23:28:27 +0200
committerSantiago Lapresta <santiago.lapresta@gmail.com>2014-12-22 22:17:53 +0100
commita3234034b5cff66cca8b32c1caf4e935d2869812 (patch)
tree2462ccaadf77d66685f27b40ab52030ac06458a4
parentb748eae03558aad2134defbecc4fadd40e3bd013 (diff)
`in` is now `inside`, added `in` as inverse of `has`
-rw-r--r--builtin.c3
-rw-r--r--docs/content/3.manual/manual.yml30
2 files changed, 25 insertions, 8 deletions
diff --git a/builtin.c b/builtin.c
index eaa7a842..8ef3153f 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1111,7 +1111,8 @@ static const char* const jq_builtins[] = {
" | reduce range(0; $max) as $j"
" ([]; . + [reduce range(0;$length) as $i ([]; . + [ $in[$i][$j] ] )] )"
" end;",
- "def in(xs): . as $x | xs | contains($x)",
+ "def in(xs): . as $x | xs | has($x)",
+ "def inside(xs): . as $x | xs | contains($x)",
};
#undef LIBM_DD
diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml
index aa8a4e2c..719b4a61 100644
--- a/docs/content/3.manual/manual.yml
+++ b/docs/content/3.manual/manual.yml
@@ -653,6 +653,22 @@ sections:
input: '[[0,1], ["a","b","c"]]'
output: ['[false, true]']
+ - title: `in`
+ body: |
+
+ The builtin function `in` returns the input key is in the
+ given object, or the input index corresponds to an element
+ in the given array. It is, essentially, an inversed version
+ of `has`.
+
+ examples:
+ - program: 'in({"foo": 42})'
+ input: '"foo", "bar"'
+ output: ['true', 'false']
+ - program: 'map(in([0,1]))'
+ input: '[2, 0]'
+ output: ['false', 'true']
+
- title: "`path(path_expression)`"
body: |
@@ -1168,27 +1184,27 @@ sections:
input: '"a,b, cd, efg, hijk"'
output: ['12']
- - title: `in`
+ - title: `inside`
body: |
- The filter `in(b)` will produce true if the input is
+ The filter `inside(b)` will produce true if the input is
completely contained within b. It is, essentially, an
inversed version of `contains`.
examples:
- - program: 'in("foobar")'
+ - program: 'inside("foobar")'
input: '"bar"'
output: ['true']
- - program: 'in(["foobar", "foobaz", "blarp"])'
+ - program: 'inside(["foobar", "foobaz", "blarp"])'
input: '["baz", "bar"]'
output: ['true']
- - program: 'in(["foobar", "foobaz", "blarp"])'
+ - program: 'inside(["foobar", "foobaz", "blarp"])'
input: '["bazzzzz", "bar"]'
output: ['false']
- - program: 'in({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})'
+ - program: 'inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})'
input: '{foo: 12, bar: [{barp: 12}]}'
output: ['true']
- - program: 'in({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})'
+ - program: 'inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})'
input: '{foo: 12, bar: [{barp: 15}]}'
output: ['false']