/php-functional-util-comparison

Comparison of functional utility libraries for PHP

Primary LanguagePHP

PHP functional utility libraries - comparison

Build Status

Which of the "functional utility libraries" for PHP is most powerful/most flexible/most pleasant to work with? This test suite should help find an answer.

Libraries compared

  • aerophant/ramda
    • pros
      • all functions curried (solves the problem of easy referencing without name constants)
    • cons
      • no documentation
  • daveross/functional-programming-utils
    • pros
    • cons
      • probably stalled (last commit 2016)
      • no collection utilities (map, flatMap, flatten, ...)
  • grrr-amsterdam/garp-functional
    • pros
      • actively maintained
    • cons
  • ihor/nspl
    • pros
      • actively maintained
      • function name constants for comfortable referencing
    • cons
      • functions split across several namespaces (import management becomes tedious)
  • kapolos/pramda
    • pros
      • passes index to map
    • cons
      • no stable release yet
      • class P not properly namespaced
      • README says "P.S. 1: Automatically Curried Functions", but it's unfortunately not true for all functions where it would be useful
      • very limited support for manual currying (see what curryN() really does)
  • kilbiller/fphp
    • pros
      • all functions curried (solves the problem of easy referencing without name constants)
    • cons
      • probably stalled (last commit 2017)
  • krak/fn
    • pros
      • actively maintained
      • each function provided both curried and uncurried
    • cons
      • most collection operations are implemented as generators (makes chaining awkward)
  • lambdish/phunctional
    • pros
      • actively maintained
      • map callback gets collection index passed
  • lodash-php/lodash-php
    • pros
      • actively maintained
      • map callback gets collection index passed
    • cons
      • basic function composition features (like compose/pipe) missing
      • many very specific utility functions
  • lstrojny/functional-php
    • pros
      • actively maintained
      • map callback gets collection and collection index passed
    • cons
      • function referencing is slightly less convenient (function name constants are not in the same namespace as the functions themselves, they are class constants of the Functional\Functional class)
  • phamda/phamda
    • pros
      • all functions curried (solves the problem of easy referencing without name constants)
    • cons
      • probably stalled (last commit 2017)

Project structure

tests/BaseTestCase.php defines test cases, each other file in the tests/ directory provides their implementation using one of the compared libraries (and PHP standard library as necessary).

Usage

$ composer install
$ vendor/bin/phpunit

License

This work is released under the CC0 "No Rights Reserved" license.