Created
January 17, 2014 16:21
-
-
Save naderman/8476251 to your computer and use it in GitHub Desktop.
Pipe - useful or not?
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 | |
require __DIR__.'/../vendor/autoload.php'; | |
use EasyBib\Pipe; | |
use iter\fn; | |
use React\Partial; | |
$leapCounter = new Pipe\Pipe(array( | |
Partial\bind('iter\map', fn\method('format', array('L'))), | |
Partial\bind('iter\reduce', function ($acc, $v) { | |
if (!isset($acc['leap'])) { | |
$acc = array('non leap' => 0, 'leap' => 0); | |
} | |
return array( | |
'non leap' => $acc['non leap'] + !$v, | |
'leap' => $acc['leap'] + $v | |
); | |
}), | |
)); | |
$result = $leapCounter(new \DatePeriod(new \DateTime('1900-01-01'), new \DateInterval('P1Y'), new \DateTime())); | |
foreach ($result as $type => $num) { | |
echo "There have been $num $type years since 1900.\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment