Den 2019-03-13 kl. 16:56, skrev Nikita Popov:
Hi internals,

Motivated by the recent list comprehensions RFC, I think it's time we took
another look at short closures:

https://wiki.php.net/rfc/arrow_functions_v2

This is based on a previous (withdrawn) proposal by Levi & Bob. It uses the
syntax

     fn($x) => $x * $multiplier

and implicit by-value variable binding. This example is roughly equivalent
to:

     function($x) use($multiplier) { return $x * $multiplier; }

The RFC contains a detailed discussion of syntax choices and binding modes.

Regards,
Nikita

Thanks for bringing this forward Nikita!

I recall from the earlier discussions 2017 that also the
lambda as a keyword was considered. I would like to
bring that forward as one option, maybe less impact
on existing code as a reserved keyword.

An advantage of not having a keyword /prefix could be
that for simple arrow functions no parenthesis is needed
and readability is improved:
$someDict->map(fn($v) => $v * 2)->filter(fn($v) => $v % 3);
$someDict->map(\($v) => $v * 2)->filter(\($v) => $v % 3);
$someDict->map(^($v) => $v * 2)->filter(^($v) => $v % 3);
vs
$someDict->map($v ==> $v * 2)->filter($v ==> $v % 3);
$someDict->map($v ~> $v * 2)->filter($v ~> $v % 3);

r//Björn L


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to