Skip to content

Commit c83ab43

Browse files
committed
Initial commit.
0 parents  commit c83ab43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2696
-0
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# PHP PSR-2 Coding Standards
5+
# http://www.php-fig.org/psr/psr-2/
6+
7+
root = true
8+
9+
[*.{php,inc,module}]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = space
15+
indent_size = 4
16+
17+
[*.{json,json.dist,yml,yml.dist}]
18+
indent_size = 4

.gitattributes

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/spec export-ignore
2+
.editorconfig export-ignore
3+
.gitattributes export-ignore
4+
.gitignore export-ignore
5+
.scrutinizer.yml export-ignore
6+
.travis.yml export-ignore
7+
phpunit.xml.dist export-ignore
8+
infection.json.dist export-ignore
9+
grumphp.yml.dist export-ignore
10+
phpspec.yml.dist export-ignore

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @loophp

.github/CODE_OF_CONDUCT.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

.github/CONTRIBUTING.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# CONTRIBUTING
2+
3+
We're using [Travis CI](https://travis-ci.com) as a continuous integration system.
4+
5+
For details, see [`.travis.yml`](../.travis.yml).
6+
7+
## Tests
8+
9+
We're using [`grumphp/grumphp`](https://github.com/phpro/grumphp) to drive the development.
10+
11+
Run
12+
13+
```bash
14+
./vendor/bin/grumphp run
15+
```
16+
17+
to run all the tests.
18+
19+
## Coding Standards
20+
21+
We are using [`drupol/php-conventions`](https://github.com/drupol/php-conventions) to enforce coding standards.
22+
23+
Run
24+
25+
```bash
26+
./vendor/bin/grumphp run
27+
```
28+
29+
to automatically detect/fix coding standard violations.

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: loophp

.github/ISSUE_TEMPLATE.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Steps required to reproduce the problem
2+
3+
1.
4+
2.
5+
3.
6+
7+
## Expected Result
8+
9+
*
10+
11+
## Actual Result
12+
13+
*

.github/PULL_REQUEST_TEMPLATE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This PR
2+
3+
* [x]
4+
* [ ]
5+
* [ ]
6+
7+
Follows #.
8+
Related to #.
9+
Fixes #.

.github/settings.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# https://github.com/probot/settings
2+
3+
labels:
4+
- name: bug
5+
color: ee0701
6+
7+
- name: dependencies
8+
color: 0366d6
9+
10+
- name: enhancement
11+
color: 0e8a16
12+
13+
- name: question
14+
color: cc317c
15+
16+
- name: security
17+
color: ee0701
18+
19+
- name: stale
20+
color: eeeeee
21+
22+
repository:
23+
allow_merge_commit: true
24+
allow_rebase_merge: false
25+
allow_squash_merge: false
26+
default_branch: master
27+
description: "A curated list of combinators"
28+
topics: combinator,combinatory-logic,functional-programming
29+
has_downloads: true
30+
has_issues: true
31+
has_pages: false
32+
has_projects: false
33+
has_wiki: false
34+
name: combinator
35+
private: false

.github/stale.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
daysUntilStale: 60
2+
3+
daysUntilClose: 7
4+
5+
staleLabel: stale
6+
7+
markComment: >
8+
This issue has been automatically marked as stale because it has not had
9+
recent activity. It will be closed if no further activity occurs. Thank you
10+
for your contributions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
on:
4+
- pull_request
5+
- push
6+
7+
name: "Continuous Integration"
8+
9+
jobs:
10+
run:
11+
name: "Grumphp"
12+
runs-on: ${{ matrix.operating-system }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
17+
php-versions: ['7.1', '7.2', '7.3', '7.4']
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@master
22+
with:
23+
fetch-depth: 1
24+
25+
- name: Install PHP
26+
uses: shivammathur/setup-php@master
27+
with:
28+
php-version: ${{ matrix.php-versions }}
29+
extensions: xdebug,mbstring
30+
31+
- name: Get Composer Cache Directory
32+
id: composer-cache
33+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
34+
35+
- name: Cache dependencies
36+
uses: actions/cache@v1
37+
with:
38+
path: ${{ steps.composer-cache.outputs.dir }}
39+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
40+
restore-keys: ${{ runner.os }}-composer-
41+
42+
- name: Install dependencies
43+
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
44+
45+
- name: Run Grumphp
46+
run: vendor/bin/grumphp run
47+
env:
48+
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
49+
50+
- name: Scrutinizer
51+
run: vendor/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml
52+
continue-on-error: true

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/composer.lock
2+
/vendor
3+
/build
4+
/.php_cs.cache
5+
/example/
6+
/.idea/
7+
/test.php
8+
/phpspec.yml

.scrutinizer.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
build:
2+
nodes:
3+
analysis:
4+
tests:
5+
override:
6+
- php-scrutinizer-run
7+
8+
filter:
9+
paths:
10+
- 'src/*'
11+
12+
tools:
13+
external_code_coverage:
14+
timeout: 600
15+
php_loc: true
16+
php_pdepend: true
17+
php_sim: true
18+
php_changetracking: true

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Pol Dellaiera
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
[![Latest Stable Version](https://img.shields.io/packagist/v/loophp/combinator.svg?style=flat-square)](https://packagist.org/packages/loophp/combinator)
2+
[![GitHub stars](https://img.shields.io/github/stars/loophp/combinator.svg?style=flat-square)](https://packagist.org/packages/loophp/combinator)
3+
[![Total Downloads](https://img.shields.io/packagist/dt/loophp/combinator.svg?style=flat-square)](https://packagist.org/packages/loophp/combinator)
4+
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/loophp/combinator/Continuous%20Integration?style=flat-square)](https://github.com/loophp/combinator/actions)
5+
[![Scrutinizer code quality](https://img.shields.io/scrutinizer/quality/g/loophp/combinator/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/loophp/combinator/?branch=master)
6+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/loophp/combinator/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/loophp/combinator/?branch=master)
7+
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/loophp/combinator/master)](https://stryker-mutator.github.io)
8+
[![License](https://img.shields.io/packagist/l/loophp/combinator.svg?style=flat-square)](https://packagist.org/packages/loophp/combinator)
9+
[![Donate!](https://img.shields.io/badge/Donate-Paypal-brightgreen.svg?style=flat-square)](https://paypal.me/drupol)
10+
11+
# Combinator
12+
13+
This package provides a list of well known Combinators.
14+
15+
A combinator is [a higher-order function](https://en.wikipedia.org/wiki/Higher-order_function) that uses only function
16+
application and earlier defined combinators to define a result from its arguments.
17+
It was introduced in 1920 by [Moses Schönfinkel](https://en.wikipedia.org/wiki/Moses_Sch%C3%B6nfinkel) and
18+
[Haskell Curry](https://en.wikipedia.org/wiki/Haskell_Curry), and has more recently been used in computer
19+
science as a theoretical model of computation and also as a basis for the design of [functional programming languages](https://en.wikipedia.org/wiki/Functional_programming_languages).
20+
Combinators which were introduced by Schönfinkel in 1920 with the idea of providing an analogous way to build up
21+
functions - and to remove any mention of variables - particularly in predicate logic.
22+
23+
## Requirements
24+
25+
* PHP >= 7.1.3
26+
27+
## Installation
28+
29+
```shell script
30+
composer require loophp/combinator
31+
```
32+
33+
## Available combinators
34+
35+
| Combinator | Definition | # Arguments |
36+
|------------|------------------------------------------|-------------|
37+
| A | `a => b => a(b)` | 2 |
38+
| B | `a => b => c => a(b(c))` | 3 |
39+
| C | `a => b => c => a(c)(b)` | 3 |
40+
| D | `a => b => c => d => a(b)(c(d))` | 4 |
41+
| E | `a => b => c => d => e => a(b)(c(d)(e))` | 5 |
42+
| F | `a => b => c => c(b)(a)` | 3 |
43+
| G | `a => b => c => d => a(d)(b(c))` | 4 |
44+
| H | `a => b => c => a(b)(c)(b)` | 3 |
45+
| I | `a => a` | 1 |
46+
| J | `a => b => c => d => a(b)(a(d)(c))` | 4 |
47+
| K | `a => b => a` | 2 |
48+
| L | `a => b => a(b(b))` | 2 |
49+
| M | `a => a(a)` | 1 |
50+
| O | `a => b => b(a(b))` | 2 |
51+
| Psi | `a => b => c => d => a((b(c))(b(d)))` | 4 |
52+
| Q | `a => b => c => b(a(c))` | 3 |
53+
| R | `a => b => c => b(c)(a)` | 3 |
54+
| S | `a => b => c => a(c)(b(c))` | 3 |
55+
| T | `a => b => b(a)` | 2 |
56+
| U | `a => b => b(a(a)(b))` | 2 |
57+
| V | `a => b => c => c(a)(b)` | 3 |
58+
| W | `a => b => a(b)(b)` | 2 |
59+
| Y | `a => (b => b(b))(b => a(c => b(b)(c)))` | 1 |
60+
61+
Example with the B combinator:
62+
63+
The definition means that the combinator needs 3 arguments: `a`, `b` and `c`.
64+
The return of this combinator is the result of the function `a` applied to the result of the function `b` applied to `c`.
65+
66+
PHP will first evaluate `b(c)` and will then pass the result to the function `a`, this is what the definition means: `a(b(c))`
67+
68+
## Usage
69+
70+
Example with [the Y combinator](https://en.wikipedia.org/wiki/Fixed-point_combinator).
71+
72+
```php
73+
<?php
74+
75+
declare(strict_types=1);
76+
77+
include 'vendor/autoload.php';
78+
79+
use loophp\combinator\Y;
80+
81+
$fibonacci = new Y(
82+
static function ($f) {
83+
return static function ($n) use ($f) {
84+
return (1 >= $n) ? $n : ($f($n - 1) + $f($n - 2));
85+
};
86+
}
87+
);
88+
89+
$result = $fibonacci()(10);
90+
```
91+
92+
## Further reading
93+
94+
- [To Mock a Mockingbird](https://en.wikipedia.org/wiki/To_Mock_a_Mockingbird)
95+
- [http://dkeenan.com/Lambda/](http://dkeenan.com/Lambda/)
96+
- https://gist.github.com/Avaq/1f0636ec5c8d6aed2e45
97+
- https://en.wikipedia.org/wiki/Combinatory_logic
98+
- https://github.com/sanctuary-js/sanctuary
99+
- https://en.wikipedia.org/wiki/Lambda_calculus
100+
101+
## Authors
102+
103+
* Pol Dellaiera

0 commit comments

Comments
 (0)