If-then-else documentation for forking conditional (fix #942)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Tolnay · committed by David Tolnay · parent c8dc164 · Browse files · 5 files·+26 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+26 added−13 removed
- tests:+14 added−1 removed
- other:+12 added−12 removed
Provenance
- Commit
6c31850- Tree
c0937b4- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
c8dc164
5 files changed+26 added−13 removed
modified:docs/content/3.manual/v1.3/manual.yml+3 added-3 removed
911 unmodified lines912 string is empty using `if .name then A else B end`, you'll913 need something more like `if (.name | count) > 0 then A else914 B end` instead.915 916- If the condition A produces multiple results, it is917- considered "true" if any of those results is not false or918- null. If it produces zero results, it's considered false.916+ If the condition `A` produces multiple results, then `B` is evaluated917+ once for each result that is not false or null, and `C` is evaluated918+ once for each false or null.919 920 More cases can be added to an if using `elif A then B` syntax.921 922 examples:348 unmodified linesmodified:docs/content/3.manual/v1.4/manual.yml+3 added-3 removed
1313 unmodified lines1314 string is empty using `if .name then A else B end`, you'll1315 need something more like `if (.name | length) > 0 then A else1316 B end` instead.1317 1318- If the condition A produces multiple results, it is1319- considered "true" if any of those results is not false or1320- null. If it produces zero results, it's considered false.1318+ If the condition `A` produces multiple results, then `B` is evaluated1319+ once for each result that is not false or null, and `C` is evaluated1320+ once for each false or null.1321 1322 More cases can be added to an if using `elif A then B` syntax.1323 1324 examples:348 unmodified linesmodified:docs/content/3.manual/v1.5/manual.yml+3 added-3 removed
1792 unmodified lines1793 string is empty using `if .name then A else B end`, you'll1794 need something more like `if (.name | length) > 0 then A else1795 B end` instead.1796 1797- If the condition A produces multiple results, it is1798- considered "true" if any of those results is not false or1799- null. If it produces zero results, it's considered false.1797+ If the condition `A` produces multiple results, then `B` is evaluated1798+ once for each result that is not false or null, and `C` is evaluated1799+ once for each false or null.1800 1801 More cases can be added to an if using `elif A then B` syntax.1802 1803 examples:1075 unmodified linesmodified:docs/content/3.manual/manual.yml+3 added-3 removed
1861 unmodified lines1862 string is empty using `if .name then A else B end`, you'll1863 need something more like `if (.name | length) > 0 then A else1864 B end` instead.1865 1866- If the condition A produces multiple results, it is1867- considered "true" if any of those results is not false or1868- null. If it produces zero results, it's considered false.1866+ If the condition `A` produces multiple results, then `B` is evaluated1867+ once for each result that is not false or null, and `C` is evaluated1868+ once for each false or null.1869 1870 More cases can be added to an if using `elif A then B` syntax.1871 1872 examples:1075 unmodified linesmodified:tests/jq.test+14 added-1 removed
865 unmodified lines866 [.[] | if .baz then "strange" elif .foo then "yep" else "nope" end]867 [{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]868 ["yep","yep","yep","yep","nope","nope","yep","nope"]869 870+[if 1,null,2 then 3 else 4 end]871+null872+[3,4,3]873 871-# FIXME: define/test behaviour of 'if (.foo,.bar) then A else B end'874+[if empty then 3 else 4 end]875+null876+[]877 878+[if 1 then 3,4 else 5 end]879+null880+[3,4]881+882+[if null then 3 else 5,6 end]883+null884+[5,6]885+886 [.[] | [.foo[] // .bar]]887 [{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]888 [[1,2], [1], [3], [42], [41]]889 412 unmodified lines