Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 20, 2020
0 parents commit c83ab43
Show file tree
Hide file tree
Showing 68 changed files with 2,696 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# PHP PSR-2 Coding Standards
# http://www.php-fig.org/psr/psr-2/

root = true

[*.{php,inc,module}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{json,json.dist,yml,yml.dist}]
indent_size = 4
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/spec export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
infection.json.dist export-ignore
grumphp.yml.dist export-ignore
phpspec.yml.dist export-ignore
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @loophp
46 changes: 46 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

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.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

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.

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.

## Scope

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.

## Enforcement

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.

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.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
29 changes: 29 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# CONTRIBUTING

We're using [Travis CI](https://travis-ci.com) as a continuous integration system.

For details, see [`.travis.yml`](../.travis.yml).

## Tests

We're using [`grumphp/grumphp`](https://github.com/phpro/grumphp) to drive the development.

Run

```bash
./vendor/bin/grumphp run
```

to run all the tests.

## Coding Standards

We are using [`drupol/php-conventions`](https://github.com/drupol/php-conventions) to enforce coding standards.

Run

```bash
./vendor/bin/grumphp run
```

to automatically detect/fix coding standard violations.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: loophp
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Steps required to reproduce the problem

1.
2.
3.

## Expected Result

*

## Actual Result

*
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This PR

* [x]
* [ ]
* [ ]

Follows #.
Related to #.
Fixes #.
35 changes: 35 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# https://github.com/probot/settings

labels:
- name: bug
color: ee0701

- name: dependencies
color: 0366d6

- name: enhancement
color: 0e8a16

- name: question
color: cc317c

- name: security
color: ee0701

- name: stale
color: eeeeee

repository:
allow_merge_commit: true
allow_rebase_merge: false
allow_squash_merge: false
default_branch: master
description: "A curated list of combinators"
topics: combinator,combinatory-logic,functional-programming
has_downloads: true
has_issues: true
has_pages: false
has_projects: false
has_wiki: false
name: combinator
private: false
10 changes: 10 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
daysUntilStale: 60

daysUntilClose: 7

staleLabel: stale

markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
52 changes: 52 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

on:
- pull_request
- push

name: "Continuous Integration"

jobs:
run:
name: "Grumphp"
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.1', '7.2', '7.3', '7.4']

steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 1

- name: Install PHP
uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-versions }}
extensions: xdebug,mbstring

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

- name: Run Grumphp
run: vendor/bin/grumphp run
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

- name: Scrutinizer
run: vendor/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml
continue-on-error: true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/composer.lock
/vendor
/build
/.php_cs.cache
/example/
/.idea/
/test.php
/phpspec.yml
18 changes: 18 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
build:
nodes:
analysis:
tests:
override:
- php-scrutinizer-run

filter:
paths:
- 'src/*'

tools:
external_code_coverage:
timeout: 600
php_loc: true
php_pdepend: true
php_sim: true
php_changetracking: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Pol Dellaiera

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.
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
[![Latest Stable Version](https://img.shields.io/packagist/v/loophp/combinator.svg?style=flat-square)](https://packagist.org/packages/loophp/combinator)
[![GitHub stars](https://img.shields.io/github/stars/loophp/combinator.svg?style=flat-square)](https://packagist.org/packages/loophp/combinator)
[![Total Downloads](https://img.shields.io/packagist/dt/loophp/combinator.svg?style=flat-square)](https://packagist.org/packages/loophp/combinator)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/loophp/combinator/Continuous%20Integration?style=flat-square)](https://github.com/loophp/combinator/actions)
[![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)
[![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)
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/loophp/combinator/master)](https://stryker-mutator.github.io)
[![License](https://img.shields.io/packagist/l/loophp/combinator.svg?style=flat-square)](https://packagist.org/packages/loophp/combinator)
[![Donate!](https://img.shields.io/badge/Donate-Paypal-brightgreen.svg?style=flat-square)](https://paypal.me/drupol)

# Combinator

This package provides a list of well known Combinators.

A combinator is [a higher-order function](https://en.wikipedia.org/wiki/Higher-order_function) that uses only function
application and earlier defined combinators to define a result from its arguments.
It was introduced in 1920 by [Moses Schönfinkel](https://en.wikipedia.org/wiki/Moses_Sch%C3%B6nfinkel) and
[Haskell Curry](https://en.wikipedia.org/wiki/Haskell_Curry), and has more recently been used in computer
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).
Combinators which were introduced by Schönfinkel in 1920 with the idea of providing an analogous way to build up
functions - and to remove any mention of variables - particularly in predicate logic.

## Requirements

* PHP >= 7.1.3

## Installation

```shell script
composer require loophp/combinator
```

## Available combinators

| Combinator | Definition | # Arguments |
|------------|------------------------------------------|-------------|
| A | `a => b => a(b)` | 2 |
| B | `a => b => c => a(b(c))` | 3 |
| C | `a => b => c => a(c)(b)` | 3 |
| D | `a => b => c => d => a(b)(c(d))` | 4 |
| E | `a => b => c => d => e => a(b)(c(d)(e))` | 5 |
| F | `a => b => c => c(b)(a)` | 3 |
| G | `a => b => c => d => a(d)(b(c))` | 4 |
| H | `a => b => c => a(b)(c)(b)` | 3 |
| I | `a => a` | 1 |
| J | `a => b => c => d => a(b)(a(d)(c))` | 4 |
| K | `a => b => a` | 2 |
| L | `a => b => a(b(b))` | 2 |
| M | `a => a(a)` | 1 |
| O | `a => b => b(a(b))` | 2 |
| Psi | `a => b => c => d => a((b(c))(b(d)))` | 4 |
| Q | `a => b => c => b(a(c))` | 3 |
| R | `a => b => c => b(c)(a)` | 3 |
| S | `a => b => c => a(c)(b(c))` | 3 |
| T | `a => b => b(a)` | 2 |
| U | `a => b => b(a(a)(b))` | 2 |
| V | `a => b => c => c(a)(b)` | 3 |
| W | `a => b => a(b)(b)` | 2 |
| Y | `a => (b => b(b))(b => a(c => b(b)(c)))` | 1 |

Example with the B combinator:

The definition means that the combinator needs 3 arguments: `a`, `b` and `c`.
The return of this combinator is the result of the function `a` applied to the result of the function `b` applied to `c`.

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))`

## Usage

Example with [the Y combinator](https://en.wikipedia.org/wiki/Fixed-point_combinator).

```php
<?php

declare(strict_types=1);

include 'vendor/autoload.php';

use loophp\combinator\Y;

$fibonacci = new Y(
static function ($f) {
return static function ($n) use ($f) {
return (1 >= $n) ? $n : ($f($n - 1) + $f($n - 2));
};
}
);

$result = $fibonacci()(10);
```

## Further reading

- [To Mock a Mockingbird](https://en.wikipedia.org/wiki/To_Mock_a_Mockingbird)
- [http://dkeenan.com/Lambda/](http://dkeenan.com/Lambda/)
- https://gist.github.com/Avaq/1f0636ec5c8d6aed2e45
- https://en.wikipedia.org/wiki/Combinatory_logic
- https://github.com/sanctuary-js/sanctuary
- https://en.wikipedia.org/wiki/Lambda_calculus

## Authors

* Pol Dellaiera
Loading

0 comments on commit c83ab43

Please sign in to comment.