letharion/functional-composable-php

Wrapper around php's array functions making them composable.

dev-master 2015-07-22 13:39 UTC

This package is not auto-updated.

Last update: 2024-05-11 13:52:17 UTC


README

Composable functional programming in PHP

Master branch status: 68747470733a2f2f7472617669732d63692e6f72672f6c6574686172696f6e2f66756e6374696f6e616c2d636f6d706f7361626c652d7068702e7376673f6272616e63683d6d6173746572

This library acts as a wrapper around several of PHP's built in array operators to provide an easy way to compose them.

Example:

<?php

require_once 'vendor/autoload.php';

use Letharion\Functional\Functional as F;

$a = [1, 2, 3, 4];

$f = new F($a);
$result = $f->walk(function(&$i) { return $i *= 2; })
  ->reduce(function($i, $j) { return $i + $j; })
  ->result();

var_dump($result);

int(20)