Skip to content

bbujisic/functional

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yet Another Take on Functional PHP

Build Status Coverage Status

Nothing special. It just adds a little bit of syntactic sugar for more expressive code.

Example

<?php

use bbujisic\functional\Collection;

$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

$sumSquaresOfOddItems = $collection
  ->filter(function ($x) { return $x % 2 == 0; })
  ->map(function ($x) { return $x * $x; })
  ->reduce(function($x, $y) { return $x + $y; });

Comparable imperative-style programming would perform a wee bit better, at a cost of lesser readability:

<?php

$collection = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$sumSquaresOfOddItems = 0;
foreach ($collection as $item) {
  if ($item % 2 == 0) {
    $sumSquaresOfOddItems += $item * $item;
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages