PHPackages                             php-slang/php-slang - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. php-slang/php-slang

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

php-slang/php-slang
===================

PHPSlang is a library that allow you to write a purely functional code in PHP

v0.1.4(9y ago)10527.2k10[22 issues](https://github.com/php-slang/php-slang/issues)2Apache2PHPPHP ~7.0CI failing

Since Oct 6Pushed 8y ago12 watchersCompare

[ Source](https://github.com/php-slang/php-slang)[ Packagist](https://packagist.org/packages/php-slang/php-slang)[ RSS](/packages/php-slang-php-slang/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (2)

PhpSlang
========

[](#phpslang)

[![Packagist](https://camo.githubusercontent.com/c2b73651a3bf98ae5a461a50976fd69a9493f6c0fe0da77f07a44e57e66b9319/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d736c616e672f7068702d736c616e672e737667)](https://packagist.org/packages/php-slang/php-slang)[![PHP from Packagist](https://camo.githubusercontent.com/8b516aa61db7461e0ef7e6ba8355408ae95372d1a45dc3aa8fef76f05516b611/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068702d736c616e672f7068702d736c616e672e737667)](https://packagist.org/packages/php-slang/php-slang)[![Build Status](https://camo.githubusercontent.com/ea4f5924b9d69741d1079d843c4f59eea8ffbcae98e959759ec97e993c50a464/68747470733a2f2f6170692e7472617669732d63692e6f72672f7068702d736c616e672f7068702d736c616e672e7376673f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://travis-ci.org/php-slang/php-slang)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c8bd5bdbf115c993d0aefef30973f6359ca98b425587c755a020e620df4d5a03/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d736c616e672f7068702d736c616e672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/php-slang/php-slang/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/d63d2b235567e4bfebf295f186cb0970368a12c2ece45d67651dfdc2d6b5a5d4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d736c616e672f7068702d736c616e672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/php-slang/php-slang/?branch=master)[![Build Status](https://camo.githubusercontent.com/02a9872fb7089657aadd7aaa799aeb30087f8f04d452a0d2019e3f6d256fe43f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d736c616e672f7068702d736c616e672f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/php-slang/php-slang/build-status/master)[![Packagist](https://camo.githubusercontent.com/d258081830f62264bb3d1b74538520e7831d3d8d37f0f0417e24ae1dd5374bf3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068702d736c616e672f7068702d736c616e672e737667)](https://packagist.org/packages/php-slang/php-slang)

[![PhpSlang](phpslang_logo.png)](phpslang_logo.png)

PhpSlang will help you to write purely functional code with PHP.

PhpSlang is a PHP library aiming to fill the gaps between PHP and classical functional languages. It provides constructs optimizing your work and letting you develop with a purely functional style.

More info
---------

[](#more-info)

[Official page](http://phpslang.io)

[Documentation](https://php-slang.github.io/php-slang-docs/static/index.html)

[Twitter](https://twitter.com/_phpslang)

[Roadmap](https://trello.com/b/amNHaAgh/phpslang-roadmap)

Features
--------

[](#features)

- [Option monad](https://php-slang.github.io/php-slang-docs/static/Usage/Essentials/Option.html)
- [Either monad](https://php-slang.github.io/php-slang-docs/static/Usage/Essentials/Either.html)
- [Copy trait](https://php-slang.github.io/php-slang-docs/static/Usage/Essentials/Copy_Trait.html)
- [Immutable List collection](https://php-slang.github.io/php-slang-docs/static/Usage/Immutable_Data_Structures/List.html)
- [Trampolines](https://php-slang.github.io/php-slang-docs/static/Usage/Trampolines.html)
- [Pattern matching](https://php-slang.github.io/php-slang-docs/static/Usage/Pattern_Matching.html)
- [Memoization](https://php-slang.github.io/php-slang-docs/static/Usage/Memoization.html)
- [Immutable HashMap collections](https://php-slang.github.io/php-slang-docs/static/Usage/Immutable_Data_Structures/HashMap.html)
- [Immutable Set collections](https://php-slang.github.io/php-slang-docs/static/Usage/Immutable_Data_Structures/Set.html)
- [Extractors](https://php-slang.github.io/php-slang-docs/static/Usage/Extractors.html)
- [Try monad](https://php-slang.github.io/php-slang-docs/static/Usage/Essentials/Try.html)
- [Future monad](https://php-slang.github.io/php-slang-docs/static/Usage/Essentials/Future.html)
- [Parallel immutable List collection](https://php-slang.github.io/php-slang-docs/static/Usage/Immutable_Data_Structures/Parallel_Collections.html)
- [Parallel immutable HashMap collection](https://php-slang.github.io/php-slang-docs/static/Usage/Immutable_Data_Structures/Parallel_Collections.html)
- [Parallel immutable Set collection](https://php-slang.github.io/php-slang-docs/static/Usage/Immutable_Data_Structures/Parallel_Collections.html)
- Traversable collections
- Numeric type with infinite precision
- Chainable\\pipe monad
- Convenient enumeration

Example code
------------

[](#example-code)

With a PhpSlang your code is going to look like that:

```
public function nonTrivialExampleFn(ParallelListCollection $mysteriousInput): float {
  return $mysteriousInput
    ->filter(function ($elem) {
      return $elem > 10;
    })
    ->partition(
      function ($elem) {
        return $elem  20;
      },
      new Set([-1, 0, 1])
    )
    ->map(function (ListCollection $bucket) {
      return $bucket->max()->getOrElse(0.0);
    })
    ->avg()
    ->getOrElse(0.0);
}
```

Or that:

```
public function actionUpdateBook(string $bookId, Request $request): Response {
  return $this
    ->bookUpdaterService
    ->updateBook($bookId, $this->bookRequestTransformer->toInput($request), $this->getUser())
    ->left(function(BookUpdateError $error) {
      return Match::val($error)->of(
        new TypeOf(BookNotFound::class, new Response(null, Response::HTTP_NOT_FOUND)),
        new TypeOf(InvalidInput::class, new Response(null, Response::HTTP_BAD_REQUEST)),
        new TypeOf(NotAuthorized::class, new Response(null, Response::HTTP_UNAUTHORIZED))
      );
    })
    ->right(function(BookInfo $bookInfo) {
      return new Response($this->bookInfoTransformer->toJson($bookInfo), Response::HTTP_OK);
    })
    ->get();
}
```

Want to see more examples? [See documentation.](https://php-slang.github.io/php-slang-docs/static/index.html)

Contribution
------------

[](#contribution)

### TL;DR;

[](#tldr)

Just feel free to post your pull requests on GitHub.

### Contribution how to

[](#contribution-how-to)

1. Fork this repository
2. Clone your fork

```
git clone git@github.com:php-slang/php-slang.git

```

2. Install dependencies

```
composer install --dev

```

3. Write some code
4. Verify if it's fine

```
./ci/verify.sh

```

5. Push your pull request!

The MIT License (MIT)
---------------------

[](#the-mit-license-mit)

Copyright (c) 2018 Witold Adamus

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Total

5

Last Release

3432d ago

PHP version history (3 changes)v0.1.0PHP &gt;=7.0.1

v0.1.2PHP &gt;=7.0.0

v0.1.4PHP ~7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/114109?v=4)[Lucas Witold Adamus](/maintainers/wit3k)[@wit3k](https://github.com/wit3k)

---

Top Contributors

[![wit3k](https://avatars.githubusercontent.com/u/114109?v=4)](https://github.com/wit3k "wit3k (2 commits)")[![akondas](https://avatars.githubusercontent.com/u/8239917?v=4)](https://github.com/akondas "akondas (1 commits)")[![IonBazan](https://avatars.githubusercontent.com/u/1985514?v=4)](https://github.com/IonBazan "IonBazan (1 commits)")[![Kryniol](https://avatars.githubusercontent.com/u/1271328?v=4)](https://github.com/Kryniol "Kryniol (1 commits)")

---

Tags

either-monadfpfunctional-programmingfuture-monadimmutabilityimmutable-phpmonadoptionalparallel-computingparallelismphpvalidationcollectionsoptionparallelfuturelazyimmutablemonadfpeithertryimmutabilitytouplefunctionalprogrammingpurelyfunctionalpatternmatchingpropertytestingtrampolines

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/php-slang-php-slang/health.svg)

```
[![Health](https://phpackages.com/badges/php-slang-php-slang/health.svg)](https://phpackages.com/packages/php-slang-php-slang)
```

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k522.3M967](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k159.6M511](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

6.0k39.9M409](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k39.7M143](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

65243.6M287](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

9216.6M70](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
