rfc:comprehensions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
rfc:comprehensions [2019/03/11 11:45] – nikic | rfc:comprehensions [2019/03/11 11:53] – fix typos in code nikic | ||
---|---|---|---|
Line 212: | Line 212: | ||
$result = array_map(function ($x) { | $result = array_map(function ($x) { | ||
- | $x * 2; | + | |
}, $list); | }, $list); | ||
Line 251: | Line 251: | ||
// but I include it for completeness. | // but I include it for completeness. | ||
$result = array_map(function($x) { | $result = array_map(function($x) { | ||
- | $x * 2 | + | |
}, array_filter(function() { | }, array_filter(function() { | ||
- | return $x % 2 | + | return $x % 2; |
}, $list)); | }, $list)); | ||
$result = (function() use ($list) { | $result = (function() use ($list) { | ||
foreach ($list as $x) { | foreach ($list as $x) { | ||
- | | + | |
yield $x * 2; | yield $x * 2; | ||
} | } | ||
Line 350: | Line 350: | ||
<code php> | <code php> | ||
$result = array_map(function($x) { | $result = array_map(function($x) { | ||
- | $x * 2 | + | |
}, array_filter(function() { | }, array_filter(function() { | ||
- | return $x % 2 | + | return $x % 2; |
}, $list)); | }, $list)); | ||
Line 371: | Line 371: | ||
<code php> | <code php> | ||
- | $result = (fn() => foreach($list as $x) if ($x % 2) yield $x * 2;)(); | + | $result = (fn() => foreach($list as $x) if ($x % 2) yield $x * 2)(); |
</ | </ | ||
rfc/comprehensions.txt · Last modified: 2019/04/05 01:10 by crell