2017 © Pedro Peláez
 

library functionalphp

Functional programming tools for PHP

image

42linoge/functionalphp

Functional programming tools for PHP

  • Thursday, May 19, 2016
  • by 42linoge
  • Repository
  • 1 Watchers
  • 0 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

FunctionalPHP

A small library porting tools from functional world (tm) to PHP. This is an ongoing effort and I'm doing it while learning about FP, along with category theory., (*1)

I've written a few tests. All functions are curried., (*2)

Writing a curried function

use CLinoge\Functional\F;

function myFunction(... $args) {
    $myFunction = F::curry(function($arg1, $arg2) {
        // Operate on $arg1 and $arg2
        return $result;
    });

    return call_user_func_array($myFunction, $args);
}

Monads, Functors

There's basic support for IO, Maybe and Left/Right. Their implementation is based upon the ideas exposed in the Mostly Adequate Guide by Dr. Boolean and RamdaJS, (*3)

Function placeholders

For a curried function n-ary f the following holds true:, (*4)

use CLinoge\Functional\Placeholder;

f(a1, a2, ..., a(N - 1), aN) == f(a1, new Placeholder, ..., new Placeholder, aN)(a2)(a(N-1));

AutoCurry objects

Experimental feature, you can test it:, (*5)

use CLinoge\Functional\CurryTransform;

$constructor = CurryTransform::take(SomeClass::class);
$object = $constructor(a1, a2, ..., aN);
$object->someMethod($a1)($a2) == $object->someMethod($a1, $a2);

Contributing

Add docs, improve perfomance, write tests :-). I'm improving this day by day and haven't still reached stable ^^., (*6)

The Versions

19/05 2016

dev-master

9999999-dev

Functional programming tools for PHP

  Sources   Download

MIT

The Development Requires

by Carlos Gottberg