Re: [RFC]Discuss] Syntax for Arrow Functions

From: Date: Mon, 19 Jun 2017 19:45:29 +0000
Subject: Re: [RFC]Discuss] Syntax for Arrow Functions
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  Groups: php.internals 
Request: Send a blank email to internals+get-99561@lists.php.net to get a copy of this message
Or maybe it'll look okay if you format the code? $things->forEach({$v => { foo($v); bar($v); }}); Still looks kinda crazy with the closing "}})" though... On Mon, Jun 19, 2017 at 9:43 PM, Rasmus Schultz <rasmus@mindplay.dk> wrote: > 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); }}); > > > On Mon, Jun 19, 2017 at 4:43 PM, Levi Morrison <levim@php.net> wrote: > >> On Sun, Jun 18, 2017 at 1:44 PM, Ilija Tovilo <ilija.tovilo@me.com> >> wrote: >> > 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. >> > >

« previous php.internals (#99561) next »