Skip to content
Myr

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

5 files+26 added−13 removed

modified:docs/content/3.manual/v1.3/manual.yml+3 added-3 removed
911 unmodified lines
912 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.915916 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.919920 More cases can be added to an if using `elif A then B` syntax.921922 examples:
348 unmodified lines
modified:docs/content/3.manual/v1.4/manual.yml+3 added-3 removed
1313 unmodified lines
1314 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.13171318 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.13211322 More cases can be added to an if using `elif A then B` syntax.13231324 examples:
348 unmodified lines
modified:docs/content/3.manual/v1.5/manual.yml+3 added-3 removed
1792 unmodified lines
1793 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.17961797 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.18001801 More cases can be added to an if using `elif A then B` syntax.18021803 examples:
1075 unmodified lines
modified:docs/content/3.manual/manual.yml+3 added-3 removed
1861 unmodified lines
1862 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.18651866 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.18691870 More cases can be added to an if using `elif A then B` syntax.18711872 examples:
1075 unmodified lines
modified:tests/jq.test+14 added-1 removed
865 unmodified lines
866[.[] | 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"]869870[if 1,null,2 then 3 else 4 end]871null872[3,4,3]873871# FIXME: define/test behaviour of 'if (.foo,.bar) then A else B end'874[if empty then 3 else 4 end]875null876[]877878[if 1 then 3,4 else 5 end]879null880[3,4]881882[if null then 3 else 5,6 end]883null884[5,6]885886[.[] | [.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