loophp/fpt

Functional programming toolbox for PHP.


Keywords
functional-programming, Toolbox
License
MIT

Documentation

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Scrutinizer code quality Type Coverage Code Coverage License Read the Docs Donate! Donate!

Functional Programming Toolbox

Description

Functional Programming Toolbox (FPT for the friends) is a set of stateless and immutable helper classes to facilitate the use of functional programming(FP) concepts.

This projects doesn't aim to transform PHP into a full featured FP language, but it will helps users willing to use and understand a subset of FP concepts in their own code.

Installation

composer require loophp/fpt

Usage

<?php

declare(strict_types=1);

namespace Example;

include __DIR__ . '/vendor/autoload.php';

use loophp\fpt\FPT;

$closure = static fn (string $first, string $second): string => sprintf("My cats names are %s and %s.", $first, $second);

$composedClosure = FPT::compose()('strtoupper', $closure);

$composedClosure('Izumi', 'Nakano'); // "MY CATS NAMES ARE IZUMI AND NAKANO."

Documentation

The API will give you a pretty good idea of the existing methods and what you can do with it.

I'm doing my best to keep the documentation up to date, if you found something odd, please let me know in the issue queue.

Code quality, tests and benchmarks

Every time changes are introduced into the library, Github run the tests.

The library has tests written with PHPSpec. Feel free to check them out in the spec directory. Run composer phpspec to trigger the tests.

Before each commit some inspections are executed with GrumPHP, run composer grumphp to check manually.

The quality of the tests is tested with Infection a PHP Mutation testing framework, run composer infection to try it.

Static analysers are also controlling the code. PHPStan and PSalm are enabled to their maximum level.

Contributing

Feel free to contribute by sending Github pull requests. I'm quite reactive :-)

If you can't contribute to the code, you can also sponsor me on Github or Paypal.

Changelog

See CHANGELOG.md for a changelog based on git commits.

For more detailed changelogs, please check the release changelogs.

Thanks

The API documentation has been inspired by the Ramda project.