rfc:arrow_function_preference

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:arrow_function_preference [2017/07/03 17:39]
levim Remove extra $
rfc:arrow_function_preference [2017/09/22 13:28] (current)
Line 55: Line 55:
 ===== Examples ===== ===== Examples =====
  
-Here are some snippets from real code-bases converted to use both syntaxes:+Here are some snippets from real code-bases converted to use the syntaxes:
  
 <PHP> <PHP>
 $s1 = fn($c) => $callable($factory($c),​ $c); $s1 = fn($c) => $callable($factory($c),​ $c);
 $s2 = {$c => $callable($factory($c),​ $c)}; $s2 = {$c => $callable($factory($c),​ $c)};
 +</​PHP>​ 
 +<PHP>
 $this->​existingSchemaPaths = array_filter($paths,​ fn($v) => in_array($v,​ $names)); $this->​existingSchemaPaths = array_filter($paths,​ fn($v) => in_array($v,​ $names));
 $this->​existingSchemaPaths = array_filter($paths,​ {$v => in_array($v,​ $names)}); $this->​existingSchemaPaths = array_filter($paths,​ {$v => in_array($v,​ $names)});
 +</​PHP>​ 
 +<PHP>
 function complement_s1(callable $f) { function complement_s1(callable $f) {
-    return fn(... $args) => !$f(... $args);+    return fn(...$args) => !$f(...$args);​
 } }
 function complement_s2(callable $f) { function complement_s2(callable $f) {
-    return {(... $args) => !$f(... $args)};+    return {(...$args) => !$f(...$args)};​
 } }
 +</​PHP>​ 
 +<PHP>
 function reject_s1($collection,​ callable $function) { function reject_s1($collection,​ callable $function) {
     return filter($collection,​ fn($value, $key) => !$function($value,​ $key));     return filter($collection,​ fn($value, $key) => !$function($value,​ $key));
Line 77: Line 80:
     return filter($collection,​ {($value, $key) => !$function($value,​ $key)});     return filter($collection,​ {($value, $key) => !$function($value,​ $key)});
 } }
 +</​PHP>​ 
 +<PHP>
 // not real code but typical of such // not real code but typical of such
 $result = Collection::​from([1,​ 2]) $result = Collection::​from([1,​ 2])
Line 90: Line 94:
  
 === Of references === === Of references ===
-As an example of all the places references can be used (needs a mono-space font for the arrows to align):+As an example of all the places references can be used:
  
     &fn &​(&​$x) => function_that_takes_ref_and_returns_ref($x,​ $y)     &fn &​(&​$x) => function_that_takes_ref_and_returns_ref($x,​ $y)
Line 106: Line 110:
     \ Variables bound from the outer-scope are bound by reference     \ Variables bound from the outer-scope are bound by reference
  
-Wes Stark suggests that we move the return-by-reference sigil to behind the parameters where we put return type information:​+[[https://​chat.stackoverflow.com/​users/​4251625/​wes-stark|Wes Stark]] suggests that we move the return-by-reference sigil to behind the parameters where we put return type information:​
  
     {($x): & => function_that_returns_ref($x,​ $y) }     {($x): & => function_that_returns_ref($x,​ $y) }
Line 112: Line 116:
            \ Function returns by reference            \ Function returns by reference
  
-This cleans up the potential density if you close by reference and return by reference. We can discuss this more if this option wins.+This cleans up the potential density if you close by reference and return by reference ​but means that we have a break in convention.
  
 === Of Nested Closures === === Of Nested Closures ===
Line 126: Line 130:
 ===== Vote ===== ===== Vote =====
  
-<doodle title="​Preference of Arrow Function Syntax for PHP 7.2" auth="​levim voteType="​single" closed="​true">​+<doodle title="​Preference of Arrow Function Syntax for PHP 7.2" auth="​levim voteType="​multi" closed="​true">​ 
 +   * Prefixed with fn 
 +   * Enclosed by curly-braces 
 +   * Reuse function 
 +   * No Preference / Other Preference 
 +</​doodle>​ 
 + 
 + 
 +<doodle title="​Practice vote for Preference of Arrow Function Syntax for PHP 7.2" auth="​levim voteType="​multi"​ closed="​TRUE">
    * Prefixed with fn    * Prefixed with fn
    * Enclosed by curly-braces    * Enclosed by curly-braces
-   * No Preference+   * Reuse function 
 +   * No Preference / Other Preference
 </​doodle>​ </​doodle>​
  
rfc/arrow_function_preference.1499103557.txt.gz · Last modified: 2017/09/22 13:28 (external edit)