# [RFC]Discuss] Syntax for Arrow Functions

- Thread: https://externals.io/message/99574
- Original archive: https://news-web.php.net/php.internals/99574
- Started by Ilija Tovilo on 2017-06-20T14:52:01+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #99574 — Ilija Tovilo — 2017-06-20T14:52:01+00:00

URL: https://externals.io/message/99574#99574

Well, the Ruby/Rust syntax would serve us well here too:

$things->forEach(|$v| {
    foo($v);
    bar($v);
});



I actually like this syntax, but what would it look like for multi-statement closures?

A nested set of curly braces around the body would look pretty messy.

    $things->forEach({$v => { foo($v); bar($v); }});




> Sorry, I wasn’t aware of that.
>
> What do you think of the Ruby/Rust style syntax that Levi proposed a while back?
>
> $someDict
>     ->map(|$v| $v * 2)
>     ->filter(|$v| $v % 3);
>
> This one has a few advantages:
>
> 1. It has syntax (a lot of) developers are already familiar with
> 2. It has no ambiguities and is fully backward compatible
> 3. It’s the shortest of all options available (two `|` characters and one space)

We determined that the arrow between the parameters and the expression
would still be required. Given this limitation I think this syntax is
seviceable:

    $someDict
        ->map({$v => $v * 2})
        ->filter({$v => $v % 3});

Sometime this week I intend to start another thread that narrows us
down to two choices.
