Download the PHP package wojciech.nawalaniec/phlambda without Composer
On this page you can find all versions of the php package wojciech.nawalaniec/phlambda. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wojciech.nawalaniec/phlambda
More information about wojciech.nawalaniec/phlambda
Files in wojciech.nawalaniec/phlambda
Package phlambda
Short Description Functional library for PHP simillar to JS Rambda (https://github.com/ramda/ramda).
License MIT
Homepage https://github.com/wnnawalaniec/phlambda
Informations about the package phlambda
[](https://travis-ci.com/wnnawalaniec/phlambda)
[](https://packagist.org/packages/wojciech.nawalaniec/phlambda)
[](https://coveralls.io/github/wnnawalaniec/phlambda?branch=master)
[](https://dashboard.stryker-mutator.io/reports/github.com/wnnawalaniec/phlambda/master)
[](https://packagist.org/packages/wojciech.nawalaniec/phlambda)
[](https://packagist.org/packages/wojciech.nawalaniec/phlambda)
[](https://packagist.org/packages/wojciech.nawalaniec/phlambda)
[](https://packagist.org/packages/wojciech.nawalaniec/phlambda)
Small library for PHP with set of usefull functions for functional programming.
Features:
- set of useful functions helpful in functional programming
- all functions are automatically currying
- every array can be wrapped with special class which allows for method chaining
- first param is always function and the data to be operated will be last param
# Table of contents
- [Installation](#installation)
- [Usage](#usage)
- [Docs](#docs)
- [Currying](#currying)
- [Development Guides](#development-guides)
- [Tools](#tools)
- [Backstory](#backstory)
# Installation
To install run:
# Usage
All functions and constants are in one namespace, so it won't create any conflict with existing ones in your project
or other libraries.
You can simply import namespaces with alias (for simplification), like this:
You can import one or few functions using import like this:
There are also constants which can be used in places accepting callbacks, because PHP
will resolve them as functions:
If you have some array and wish to perform multiple, chained operations on it. You can wrapp it
with special object with `_()` function:
If you wish to have more readable code you can use a static method from that class instead: `Wrapper::wrap($array)`.
If you don't want to use objects you can use just functions. Wrapper's methods are just delegates to those functions,
and exists only for chaining purposes.
# Docs
[Here you can find documentation.](https://wnnawalaniec.github.io/phlambda/packages/Application.html)
# Currying
What makes that library different from other functional libraries for PHP is that all function are automatically curried.
If you don't know what currying functions are let me try to change it.
According to [Wikipedia](https://en.wikipedia.org/wiki/Currying):
> In mathematics and computer science, currying is the technique of converting a function that takes multiple arguments into a sequence of functions that each takes a single argument.
Let's see an example:
Because I've decided to implement currying, I've also added placeholder feature. A placeholder is special type you can
pass to currying function, if you want to postpone passing of some arguments.
Example of placeholder usage:
# Development Guides
Check out [CONTRIBUTING file](https://github.com/wnnawalaniec/phlambda/blob/master/CONTRIBUTING.md)
## Tools
- `make build-docs` - generates HTML documentation. *Requires [Docker](https://www.docker.com/) installed*
- `make generate-constants` - generates `src/constants.php` file, for all functions
# Backstory
PHP was not designed as functional programming language, that's one thing I'm sure.
We can create and use anonymous functions, and in `7.4` we even got arrow functions `fn () =>`.
Language itself is providing us with some functions like `array_map()` etc. where we can pass an array
and some callable to perform some operations on the input.
But its... so cumbersome.
One day at the company my friend joked about PHP and said that it's sad we can't do something like this in PHP:
I thought for a while, and respond with something like this:
Both examples are similar, but we can see that with PHP solution we have no way of chaining methods together, also we
must write most of that method our selves. After while another idea came up to my mind. We could leverage OOP and create
class which implements `\ArrayAccess` so it can be considered array like, and have all that nice methods we can chain together.
I thought about something like this:
It seemed as a great weekend project so here it is.
There are some great functional libraries for JS, but one (pointed by earlier mentioned friend) seemed interesting.
It's [Ramda](https://github.com/ramda/ramda). It's interesting because it has all function automatically curried, and it
adds some complexity to that project.
All versions of phlambda with dependencies
ext-mbstring Version *