Created
March 31, 2017 08:05
-
-
Save stelt/5730c8e9767a6ba52979c97a7cc0ab63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function select($arr, $callback){ | |
foreach ($arr as $value) { | |
if($callback($value)) | |
yield $value; | |
} | |
} | |
$arr = [1, 2, 3, 4, 5, 6, 7, 8]; | |
$select = select($arr, function($e){return $e % 2 == 0 ? true : false;}); | |
$collect = collect($select, function($e){return $e * $e;}); | |
foreach ($select as $val) | |
echo $val; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment