Permalink
Browse files

init

  • Loading branch information...
0 parents commit 9f0c1c55b1a44710b777ed5a892f4949e8edb93d @igorw igorw committed Aug 31, 2012
Showing with 195 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +10 −0 .travis.yml
  3. +19 −0 LICENSE
  4. +44 −0 README.md
  5. +12 −0 composer.json
  6. +14 −0 composer.lock
  7. +14 −0 examples/curry.php
  8. +25 −0 phpunit.xml.dist
  9. +16 −0 src/React/Curry/Util.php
  10. +36 −0 tests/React/Curry/UtilTest.php
  11. +4 −0 tests/bootstrap.php
@@ -0,0 +1 @@
+vendor
@@ -0,0 +1,10 @@
+language: php
+
+php:
+ - 5.3
+ - 5.4
+
+before_script:
+ - composer install
+
+script: phpunit --coverage-text
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Igor Wiedler
+
+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.
@@ -0,0 +1,44 @@
+# React/Curry
+
+Currying.
+
+[![Build Status](https://secure.travis-ci.org/react-php/curry.png?branch=master)](http://travis-ci.org/react-php/curry)
+
+## Install
+
+The recommended way to install react/curry is [through composer](http://getcomposer.org).
+
+```JSON
+{
+ "require": {
+ "react/curry": "dev-master"
+ }
+}
+```
+
+## Example
+
+```php
+<?php
+
+use React\Curry\Util as Curry;
+
+$add = function ($a, $b) {
+ return $a + $b;
+};
+
+$addOne = Curry::bind($add, 1);
+
+echo sprintf("%s\n", $addOne(5));
+// outputs 6
+```
+
+## Tests
+
+To run the test suite, you need PHPUnit.
+
+ $ phpunit
+
+## License
+
+MIT, see LICENSE.
@@ -0,0 +1,12 @@
+{
+ "name": "react/curry",
+ "description": "Currying.",
+ "keywords": ["curry", "currying", "functional-programming"],
+ "license": "MIT",
+ "require": {
+ "php": ">=5.3.2"
+ },
+ "autoload": {
+ "psr-0": { "React\\Curry": "src" }
+ }
+}
@@ -0,0 +1,14 @@
+{
+ "hash": "99a72de187b9d4240a4e32c6c68eec1e",
+ "packages": [
+
+ ],
+ "packages-dev": null,
+ "aliases": [
+
+ ],
+ "minimum-stability": "stable",
+ "stability-flags": [
+
+ ]
+}
@@ -0,0 +1,14 @@
+<?php
+
+require __DIR__.'/../vendor/autoload.php';
+
+use React\Curry\Util as Curry;
+
+$add = function ($a, $b) {
+ return $a + $b;
+};
+
+$addOne = Curry::bind($add, 1);
+
+echo sprintf("%s\n", $addOne(5));
+// outputs 6
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="React/Curry Test Suite">
+ <directory>./tests/React/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./src/</directory>
+ </whitelist>
+ </filter>
+</phpunit>
@@ -0,0 +1,16 @@
+<?php
+
+namespace React\Curry;
+
+class Util
+{
+ public static function bind(/*$fn, $args...*/)
+ {
+ $args = func_get_args();
+ $fn = array_shift($args);
+
+ return function () use ($fn, $args) {
+ return call_user_func_array($fn, array_merge($args, func_get_args()));
+ };
+ }
+}
@@ -0,0 +1,36 @@
+<?php
+
+namespace React\Curry;
+
+use React\Curry\Util as Curry;
+
+class UtilTest extends \PHPUnit_Framework_TestCase
+{
+ public function testBindWithNoArgs()
+ {
+ $add = $this->createAddFunction();
+ $newAdd = Curry::bind($add);
+ $this->assertSame(6, $newAdd(1, 5));
+ }
+
+ public function testBindWithOneArg()
+ {
+ $add = $this->createAddFunction();
+ $addOne = Curry::bind($add, 1);
+ $this->assertSame(6, $addOne(5));
+ }
+
+ public function testBindWithTwoArgs()
+ {
+ $add = $this->createAddFunction();
+ $addOneAndFive = Curry::bind($add, 1, 5);
+ $this->assertSame(6, $addOneAndFive());
+ }
+
+ public function createAddFunction()
+ {
+ return function ($a, $b) {
+ return $a + $b;
+ };
+ }
+}
@@ -0,0 +1,4 @@
+<?php
+
+$loader = require __DIR__.'/../vendor/autoload.php';
+$loader->add('React\\Curry', __DIR__);

0 comments on commit 9f0c1c5

Please sign in to comment.