You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Like the title says, the examples in the documentation are examples of partial application. Currying is when a function with 4 arguments is turned in to a function with 1 argument that produces a function with 1 argument that produces a function with 1 argument that produces a function with 1 argument that produces the result.
the examples in the documentation are examples of partial application
Agreed.
Currying is when a function with 4 arguments is turned in to a function with 1 argument that produces a function with 1 argument that produces a function with 1 argument that produces a function with 1 argument that produces the result.
Agreed.
This library does partial application, not currying
I'd say it does both, and it uses the same curry function for both.
As I was writing a test to explore the behaviour, I also discovered that partial application requires an additional () when you pass all the arguments. Not a big deal, but still a bug imho.
<?phpusePHPUnit\Framework\TestCase;
usefunctionCypress\Curry\curry;
finalclass CurryTest extends TestCase
{
/** @test */publicfunctioncurry()
{
$f = fn($a, $b, $c) => $a + $b + $c;
$curried = curry($f);
$this->assertIsCallable($curried);
$this->assertIsCallable($curried(1));
$this->assertIsCallable($curried(1)(2));
$this->assertIsCallable($curried(1)(2));
$this->assertEquals(6, $curried(1)(2)(3));
}
/** @test */publicfunctionpartial_application()
{
$f = fn($a, $b, $c) => $a + $b + $c;
$this->assertIsCallable(curry($f, 1));
$this->assertIsCallable(curry($f, 1, 2));
// I would expect this:$this->assertEquals(6, curry($f, 1, 2, 3));
// But we must add a () at the end, which I feel is a bug:$this->assertIsCallable(curry($f, 1, 2, 3));
$this->assertEquals(6, curry($f, 1, 2, 3)());
}
}
Like the title says, the examples in the documentation are examples of partial application. Currying is when a function with 4 arguments is turned in to a function with 1 argument that produces a function with 1 argument that produces a function with 1 argument that produces a function with 1 argument that produces the result.
https://en.wikipedia.org/wiki/Currying
The text was updated successfully, but these errors were encountered: