Re: Re: [RFC][Discuss] Arrow Functions
| From: | Fleshgrinder | Date: | Fri, 03 Feb 2017 22:41:07 +0000 |
| Subject: | Re: Re: [RFC][Discuss] Arrow Functions | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98150@lists.php.net to get a copy of this message | ||
On 2/3/2017 11:26 PM, Michael Morris wrote:
> On Fri, Feb 3, 2017 at 3:37 PM, Niklas Keller <me@kelunik.com> wrote:
>>
>>
>> There are more drawbacks to that syntax like no parameters looking pretty
>> weird: || =>
>>
>>
> I can't think of a valid example of an arrow function without any arguments
> at all. These functions are very simple iterators to plug into things like
> array_map. If you can think of one please post it.
>
There are many situations where one might want a closure that takes no
arguments.
```
$option->unwrapOrThrow(|| => new Exception('my message'));
```
Creating a supplier callable is often less resource intensive than
actually computing the supplied value.
Rust has exactly that syntax but it can become rather cryptic and PHP is
a verbose language in general. I think that it is best for PHP to go for
function to keep things nicely aligned and to avoid problems with
union types (which we really need).
--
Richard "Fleshgrinder" Fussenegger