May 2017
Intermediate to advanced
340 pages
8h 16m
English
Currying is a technique of transforming a function that takes multiple arguments to a chain of functions where each function will take exactly one argument. In other words, if a function can be written as f(x,y,z), then the currying version of this will be f(x)(y)(z). let's consider the following example:
function sum($a, $b, $c) { return $a + $b + $c;}
Here, we have written a simple function with three parameters and when called with numbers, it will return sum of the numbers. Now, if we write this function as a curry, it will look like this:
function currySum($a) { return function($b) use ($a) { return function ($c) use ($a, $b) { return $a + $b + $c; }; }; } $sum = currySum(10)(20)(30); echo $sum;
Now if we run the currySum ...
Read now
Unlock full access