PHP code example of cypresslab / php-curry

1. Go to this page and download the library: Download cypresslab/php-curry library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cypresslab / php-curry example snippets


$add = function($x, $y)
{ 
	return $x + $y; 
};
$reduce = C\curry('array_reduce');
$sum = $reduce(C\__(), $add);

echo $sum([1, 2, 3, 4], 0); // output 10
 php
use Cypress\Curry as C;

$adder = function ($a, $b, $c, $d) {
  return $a + $b + $c + $d;
};

$firstTwo = C\curry($adder, 1, 2);
echo $firstTwo(3, 4); // output 10

$firstThree = $firstTwo(3);
echo $firstThree(14); // output 20
 bash
composer 
 php
$divider = function ($a, $b) {
    return $a / $b;
};

$divide10By = C\curry($divider, 10);
$divideBy10 = C\curry_right($divider, 10);

echo $divide10By(10); // output 1
echo $divideBy10(100); // output 10
 php
use Cypress\Curry as C;

$divider = function ($a, $b) {
    return $a / $b;
};

$division = C\curry_args($divider, [100, 10]);
echo $division(); // output 10

$division2 = C\curry_right_args($divider, [100, 10]);
echo $division2(); // output 0.1
 php
$haystack = "haystack";
$searches = ['h', 'a', 'z'];
$strpos = C\curry('strpos', $haystack); // You can pass function as string too!
var_dump(array_map($strpos, $searches)); // output [0, 1, false]
 php
$haystack = "haystack";
$searches = ['h', 'a', 'z'];
$strpos = C\curry_fixed(3, 'strpos', $haystack);
$finders = array_map($strpos, $searches);
var_dump(array_map(function ($finder) {
    return $finder(2);
}, $finders)); // output [false, 5, false]