Functional primitives for PHP

Having coded functional Haskell for a while now, I feel my imperative coding style is changing as a result. This primarily means PHP nowadays. While I really do enjoy a lot of aspects of this language, I will be the first to admit it lacks certain elegance.

There is no list comprehension, partial function application is bothersome, you can not overload methods, etc. PHP just is not designed for functional programming. Still, I believe your code can benefit from taking on a more functional approach.

To help with this endeavor; there is Functional primitives for PHP — a PHP library for coding in a functional and consistent manner.

  • It does not only work with arrays, but anything implementing the Traversable interface.

  • All its functions consistently takes a collection as a first parameter and a callback as a second parameter.

  • Callbacks are always given the current value, its index and the entire collection.

  • Any callable is a valid callback, whether that is a string function, an array with an object method or a closure.

  • There is both a userland (Composer managed!) PHP library and an extension in C for performance.

Go check it out at its GitHub repository! Kudos to Igor Wiedler for recommending it.