On Wed, Dec 16, 2020 at 6:50 PM someniatko <somenia...@gmail.com> wrote: > > `match` is an expression, where as if-else construction is not. This > allows for combining it with a potential future feature of single line > functions and methods. For example (hypothetical syntax is used): > > ``` > $getNumber = fn(int $number) => match { > $number < 0 => NumberKind::NEGATIVE, > $number == 0 => NumberKind::ZERO, > $number > 0 => NumberKind::POSITIVE, > }; > ``` >
That does read attractively, yes. This is the example that should have been offered first as it shows the expression nature shining. To contrast that with what would be possible now in an expressive functional form: $getNumber = fn(int $number) => [ -1 => NumberKind::NEGATIVE, 0 => NumberKind::ZERO, 1 => NumberKind::POSITIVE, ][$number <=> 0]; The match form *certainly* reads more naturally than the spaceship indexing form even though both take up equal space. -Sara