2017 © Pedro Peláez
 

library php-fp

Functional Programming Helpers

image

camspiers/php-fp

Functional Programming Helpers

  • Monday, August 25, 2014
  • by camspiers
  • Repository
  • 3 Watchers
  • 16 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Functional Programming Helpers

Currying

A curryable function returns a new function when called with less arguments than the curryable function requires. The new function returned will have the arguments applied, and will also be a curryable function., (*1)

This programming pattern can be used to build up more complex functions from less complex functions., (*2)

e.g., (*3)

// Create a curryable function
$concat = fp\curry(function ($a, $b) { return $a . $b; });

// Create a new function with 'Mr. ' applied
$addTitle = $concat('Mr. ');

echo $addTitle('Spiers');
// Mr. Spiers

Composition

$h = fp\compose($f, $g);

Function composition will return a new function ($h) which will first apply the second function ($g), pass its result into the first ($f)., (*4)

Usage

Turning normal functions into curryable functions

$map = fp\curry('array_map');

Create non-closure functions that are curryable

function _tag($tag, $text) {
    return "<$tag>$text</$tag>";
}

function tag(...$args) {
    return fp\curry('_tag')->__invoke(...$args);
}

// We now have a paragraph function
$p = tag('p');

// We now have a div function
$div = tag('div');

echo $div($p("Some text"));
// 

Some text, (*5)

The Versions

25/08 2014

dev-master

9999999-dev

Functional Programming Helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

13/08 2014

0.2.1

0.2.1.0

Functional Programming Helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

11/08 2014

0.2.0

0.2.0.0

Functional Programming Helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

11/08 2014

0.1.2

0.1.2.0

Functional Programming Helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

11/08 2014

0.1.1

0.1.1.0

Functional Programming Helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

10/08 2014

0.1.0

0.1.0.0

Functional Programming Helpers

  Sources   Download

MIT

The Requires

 

The Development Requires