rfc:short-match
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:short-match [2020/12/14 00:18] – crell | rfc:short-match [2022/04/17 19:06] (current) – Move to inactive ilutov | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2020-12-13 | * Date: 2020-12-13 | ||
* Author: Larry Garfield (larry@garfieldtech.com) | * Author: Larry Garfield (larry@garfieldtech.com) | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 15: | Line 15: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC makes only one change. | + | This RFC would make only one change. |
That is, this PHP 8.0 syntax: | That is, this PHP 8.0 syntax: | ||
Line 29: | Line 29: | ||
</ | </ | ||
- | Can, with this RFC, be shortened to: | + | could, with this RFC, be shortened to: |
<code php> | <code php> | ||
Line 41: | Line 41: | ||
</ | </ | ||
+ | A prime use case for such match statements is for basic pattern matching within a function: | ||
+ | |||
+ | <code php> | ||
+ | function getNumberKind(int $num) { | ||
+ | return match { | ||
+ | $num > 0 => NumberKind:: | ||
+ | $num == 0 => NumberKind:: | ||
+ | $num < 0 => NumberKind:: | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | That would be even more compact if combined with the also-proposed [[rfc: | ||
+ | |||
+ | <code php> | ||
+ | $getNumber = fn(int $num) => match { | ||
+ | $num < 0 => NumberKind:: | ||
+ | $num == 0 => NumberKind:: | ||
+ | $num > 0 => NumberKind:: | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | The net result is to simplify both the writing and reading of " | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 53: | Line 76: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | This is a simple up-or-down vote, requiring | + | Accept this RFC as proposed. |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 66: | Line 89: | ||
* [[rfc: | * [[rfc: | ||
* [[rfc: | * [[rfc: | ||
+ | * [[rfc: |
rfc/short-match.1607905100.txt.gz · Last modified: 2020/12/14 00:18 by crell