PHPackages                             tarsana/functional - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tarsana/functional

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tarsana/functional
==================

functional programming library for PHP

2.2.2(7y ago)542.2k↓88.9%1MIT

Since Aug 28Compare

[ Source](https://github.com/tarsana/functional)[ Packagist](https://packagist.org/packages/tarsana/functional)[ RSS](/packages/tarsana-functional/feed)WikiDiscussions Synced yesterday

READMEChangelog (7)Dependencies (1)Versions (9)Used By (1)

Tarsana Functional
==================

[](#tarsana-functional)

[![Build Status](https://camo.githubusercontent.com/7a63986d798599655b8f0866a2a3a0ce12361e9cbad2a4ef44c6bab1c63b5806/68747470733a2f2f7472617669732d63692e6f72672f74617273616e612f66756e6374696f6e616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tarsana/functional)[![Coverage Status](https://camo.githubusercontent.com/01517f8a3d5534dea298da71a54e69265368492c26e8aed4f7b45c196d7a257b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f74617273616e612f66756e6374696f6e616c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/tarsana/functional?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d5b7651aaf655f8ce20837ad4c6835ae4e58a958cf7a45b17e694a0a02fa0f74/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74617273616e612f66756e6374696f6e616c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tarsana/functional/?branch=master)[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.me/webneat)[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/tarsana/functional/blob/master/LICENSE)

Functional programming library for PHP.

Table of Contents
=================

[](#table-of-contents)

- [Introduction](#introduction)
- [Get Started](#get-started)
- [Features](#features)
- [Functions](#functions)
- [Classes](#classes)
- [Tests](#tests)
- [Contributing](#contributing)
- [Changes Log](#changes-log)

Introduction
============

[](#introduction)

**What is that ?**

This is a [Functional Programming](https://en.wikipedia.org/wiki/Functional_programming) library for PHP.

**Why Functional Programming ? Isn't Object Oriented good enough ?**

Well, it dependes on your needs. FP and OOP are very different. Personally I like FP because the code is easier to write, test and maintain; even if it runs generally slower than the equivalent procedural or OOP code.

**Just Googled and found many FP libraries for PHP. Why are you writing a new one ?**

This library is inspired by [Ramda](http://ramdajs.com/) which is a FP library for Javascript. Ramda was created after [underscore](http://underscorejs.org/) and [lodash](https://lodash.com/) and it has a better Functional API then others. [This talk explains how](https://www.youtube.com/watch?v=m3svKOdZijA&app=desktop). So I wanted a library with the same philisophy as Ramda supporting old versions of PHP (from version 5.4).

Get Started
===========

[](#get-started)

You can install this library using [composer](https://getcomposer.org/)

```
composer require tarsana/functional

```

Then you can use it by importing the `Tarsana\Functional` namespace.

```
use Tarsana\Functional as F;
// all functions are defined in this namespace

$incrementAll = F\map(F\plus(1));

$incrementAll([1, 2, 3]); //=> [2, 3, 4]
```

Features
========

[](#features)

The main features of this library are:

- [Ramda](http://ramdajs.com/) like functional API with [curry()](https://github.com/tarsana/functional/blob/master/docs/functions.md#curry) and [\_\_()](https://github.com/tarsana/functional/blob/master/docs/functions.md#__).
- **100+** Functions covered with **140+** Tests Cases containing **390+** assertions.
- All functions are **curried** out of the box.
- No dependencies !
- Supporting PHP versions since **5.4**
- Flexible [Stream](https://github.com/tarsana/functional/blob/master/docs/stream.md) class.

Functions
=========

[](#functions)

Functions are grouped into modules

- [Functions](https://github.com/tarsana/functional/blob/master/docs/functions.md)
- [List](https://github.com/tarsana/functional/blob/master/docs/list.md)
- [Object](https://github.com/tarsana/functional/blob/master/docs/object.md)
- [String](https://github.com/tarsana/functional/blob/master/docs/string.md)
- [Math](https://github.com/tarsana/functional/blob/master/docs/math.md)
- [Operators](https://github.com/tarsana/functional/blob/master/docs/operators.md)
- [Common](https://github.com/tarsana/functional/blob/master/docs/common.md)

Classes
=======

[](#classes)

**Why classes ? Isn't that a FUNCTIONAL library ?**

We can use classes to define Types and Containers as long as they are **immutable** and have **pure methods**. Defining a container as a class gives us a fluent API and elegant code.

The main class defined in this library is `Stream`. It's an immutable data container with lazy evaluation and type errors detection. It will allow you to write code like the following:

```
