Implement flatten/0 in terms of flatten/1
This commit is contained in:
1 parent
16e8d0b1ab
commit
3d49fc59dd
2 files changed
+12
-4
No files matched your search
@@ -1420,8 +1420,9 @@ static const char* const jq_builtins[] = {
|
||||
"def scalars_or_empty: select(. == null or . == true or . == false or type == \"number\" or type == \"string\" or ((type==\"array\" or type==\"object\") and length==0));",
|
||||
"def leaf_paths: paths(scalars);",
|
||||
"def join($x): reduce .[] as $i (null; (.//\"\") + (if . == null then $i else $x + $i end))//\"\";",
|
||||
"def flatten: reduce .[] as $i ([]; if $i | type == \"array\" then . + ($i | flatten) else . + [$i] end);",
|
||||
"def flatten($x): reduce .[] as $i ([]; if $i | type == \"array\" and $x > 0 then . + ($i | flatten($x-1)) else . + [$i] end);",
|
||||
"def _flatten($x): reduce .[] as $i ([]; if $i | type == \"array\" and $x != 0 then . + ($i | _flatten($x-1)) else . + [$i] end);",
|
||||
"def flatten($x): if $x < 0 then error(\"flatten depth must not be negative\") else _flatten($x) end;",
|
||||
"def flatten: _flatten(-1);",
|
||||
"def range($x): range(0;$x);",
|
||||
"def fromdateiso8601: strptime(\"%Y-%m-%dT%H:%M:%SZ\")|mktime;",
|
||||
"def todateiso8601: strftime(\"%Y-%m-%dT%H:%M:%SZ\");",
|
||||
|
||||
Reference in new issue
Block a user