{"id":37007121,"url":"https://github.com/wnnawalaniec/phlambda","last_synced_at":"2026-01-14T00:46:27.095Z","repository":{"id":45046385,"uuid":"444469235","full_name":"wnnawalaniec/phlambda","owner":"wnnawalaniec","description":"Functional library for PHP simillar to JS Rambda (https://github.com/ramda/ramda).","archived":false,"fork":false,"pushed_at":"2022-12-02T20:10:10.000Z","size":287,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-19T09:43:40.240Z","etag":null,"topics":["functional","functional-programming","functions","library","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wnnawalaniec.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-04T15:27:02.000Z","updated_at":"2022-06-16T22:18:44.000Z","dependencies_parsed_at":"2023-01-22T14:00:28.587Z","dependency_job_id":null,"html_url":"https://github.com/wnnawalaniec/phlambda","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/wnnawalaniec/phlambda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnnawalaniec%2Fphlambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnnawalaniec%2Fphlambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnnawalaniec%2Fphlambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnnawalaniec%2Fphlambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wnnawalaniec","download_url":"https://codeload.github.com/wnnawalaniec/phlambda/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnnawalaniec%2Fphlambda/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406568,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional","functional-programming","functions","library","php"],"created_at":"2026-01-14T00:46:26.989Z","updated_at":"2026-01-14T00:46:27.065Z","avatar_url":"https://github.com/wnnawalaniec.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n \u003cimg src=\"https://i.ibb.co/44kx283/repository-open-graph-template2.png\"/\u003e\n\u003c/a\u003e\n\n[![Build Status](https://travis-ci.com/wnnawalaniec/phlambda.svg?branch=master)](https://travis-ci.com/wnnawalaniec/phlambda)\n[![Version](http://poser.pugx.org/wojciech.nawalaniec/phlambda/version)](https://packagist.org/packages/wojciech.nawalaniec/phlambda)\n[![Coverage Status](https://coveralls.io/repos/github/wnnawalaniec/phlambda/badge.svg?branch=master)](https://coveralls.io/github/wnnawalaniec/phlambda?branch=master)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fwnnawalaniec%2Fphlambda%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/wnnawalaniec/phlambda/master)\n[![Latest Stable Version](http://poser.pugx.org/wojciech.nawalaniec/phlambda/v)](https://packagist.org/packages/wojciech.nawalaniec/phlambda)\n[![Total Downloads](http://poser.pugx.org/wojciech.nawalaniec/phlambda/downloads)](https://packagist.org/packages/wojciech.nawalaniec/phlambda)\n[![License](http://poser.pugx.org/wojciech.nawalaniec/phlambda/license)](https://packagist.org/packages/wojciech.nawalaniec/phlambda)\n[![PHP Version Require](http://poser.pugx.org/wojciech.nawalaniec/phlambda/require/php)](https://packagist.org/packages/wojciech.nawalaniec/phlambda)\n\nSmall library for PHP with set of usefull functions for functional programming.\n\nFeatures:\n - set of useful functions helpful in functional programming\n - all functions are automatically currying\n - every array can be wrapped with special class which allows for method chaining\n - first param is always function and the data to be operated will be last param\n \n# Table of contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Docs](#docs)\n- [Currying](#currying)\n- [Development Guides](#development-guides)\n  - [Tools](#tools)\n- [Backstory](#backstory)\n\n# Installation\nTo install run:\n```\ncomposer require wojciech.nawalaniec/phlambda\n```\n\n# Usage\nAll functions and constants are in one namespace, so it won't create any conflict with existing ones in your project\nor other libraries.\nYou can simply import namespaces with alias (for simplification), like this:\n```php\nuse Wojciech\\Phlambda as f;\n\nf\\all(f\\above(2), [1, 2, 3, 4]);\n```\n\nYou can import one or few functions using import like this:\n```php\nuse function Wojciech\\Phlambda\\{all, above};\n\nall(above(2), [1, 2, 3, 4]);\n```\n\nThere are also constants which can be used in places accepting callbacks, because PHP\nwill resolve them as functions:\n```php\nuse function Wojciech\\Phlambda\\map;\nuse const Wojciech\\Phlambda\\toString;\n\nmap(toString, [1, 2, 3]);\n```\n\nIf you have some array and wish to perform multiple, chained operations on it. You can wrapp it\nwith special object with `_()` function:\n\n```php\nuse function Wojciech\\Phlambda\\{_, below, concat};\nuse const Wojciech\\Phlambda\\toString;\n\n_($someArray)\n    -\u003efilter(below(30))\n    -\u003emap(toString) // you can use constant which will be resolved as callable by PHP\n    -\u003ereduce(concat(), ''); // or you can call function without params because all functions all curried\n```\n\nIf you wish to have more readable code you can use a static method from that class instead: `Wrapper::wrap($array)`.\n\nIf you don't want to use objects you can use just functions. Wrapper's methods are just delegates to those functions,\nand exists only for chaining purposes.\n\n# Docs\n[Here you can find documentation.](https://wnnawalaniec.github.io/phlambda/packages/Application.html)\n\n# Currying\nWhat makes that library different from other functional libraries for PHP is that all function are automatically curried.\nIf you don't know what currying functions are let me try to change it.\nAccording to [Wikipedia](https://en.wikipedia.org/wiki/Currying):\n\u003e 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.\n\nLet's see an example:\n ```php\n// we can use reduce function normally like this:\n$array = ['a', 'b', 'c'];\n$result = reduce(\\Wojciech\\Phlambda\\concat, '', $array); // $result = 'abc'\n\n// and we can use it like currying function:\n$concat = reduce(\\Wojciech\\Phlambda\\concat, ''); // now it will return callback accepting last param from reduce - an array\n$result = $concat($array); // $result = 'abc'\n```\n\nBecause I've decided to implement currying, I've also added placeholder feature. A placeholder is special type you can \npass to currying function, if you want to postpone passing of some arguments.\n\nExample of placeholder usage:\n```php\n$array = [1, 2, 3];\n$reducer = reduce(__, __, $array);\n\n$sum = $reducer(sum, 0);\n$multiplication = $reducer(multiply, 0);\n```\n\n# Development Guides\nCheck out [CONTRIBUTING file](https://github.com/wnnawalaniec/phlambda/blob/master/CONTRIBUTING.md)\n\n## Tools\n - `make build-docs` - generates HTML documentation. *Requires [Docker](https://www.docker.com/) installed*\n - `make generate-constants` - generates `src/constants.php` file, for all functions\n\n# Backstory\nPHP was not designed as functional programming language, that's one thing I'm sure. \nWe can create and use anonymous functions, and in `7.4` we even got arrow functions `fn () =\u003e`.\nLanguage itself is providing us with some functions like `array_map()` etc. where we can pass an array\nand some callable to perform some operations on the input.\nBut its... so cumbersome.\n\nOne day at the company my friend joked about PHP and said that it's sad we can't do something like this in PHP:\n```js\nsomeArray.every(below(30));\n```\n\nI thought for a while, and respond with something like this:\n```php\nfunction below(int $val): callable\n{\n    return fn(int $v) =\u003e $v \u003c $val;\n}\n\nfunction every(array $a, callable $fn): array\n{\n    return array_filter($a, $fn);\n}\n\n$arr = [1, 2, 3, 4];\nevery($arr, below(3));\n```\n\nBoth examples are similar, but we can see that with PHP solution we have no way of chaining methods together, also we\nmust write most of that method our selves. After while another idea came up to my mind. We could leverage OOP and create\nclass which implements `\\ArrayAccess` so it can be considered array like, and have all that nice methods we can chain together.\nI thought about something like this:\n```php\n$arrayObject\n    -\u003efilter(below(30))\n    -\u003esum();\n```\nIt seemed as a great weekend project so here it is.\n\nThere are some great functional libraries for JS, but one (pointed by earlier mentioned friend) seemed interesting.\nIt's [Ramda](https://github.com/ramda/ramda). It's interesting because it has all function automatically curried, and it\nadds some complexity to that project.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwnnawalaniec%2Fphlambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwnnawalaniec%2Fphlambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwnnawalaniec%2Fphlambda/lists"}