pawaclawczyk / scalp

Some Scala useful classes ported to PHP.
18 stars 1 forks source link

Currying? #21

Closed shadowhand closed 7 years ago

shadowhand commented 7 years ago

I see that scalp has a partial function, but it looks like said function expects that all arguments will be passed during invocation. What would it take to add a currying?

pawaclawczyk commented 7 years ago

I think it's great idea and currying will be a nice tool next to PFA.

I assume that curry function should take N-arguments function and return a function with N-1 arity. With this assumption it should return the passed function for 0 or 1 argument functions.

$cuboidVolume = function (int $a, int $b, int $h): int {
    return $a * $b * $c;
};

$curriedVolume = curry($cuboidVolume);

$res0 = $curriedVolume(3, 2)(5);

// $res0 === 30

I'm not sure if we need reverse function -- uncurry.

I think I'll be done with the first implementation this week.

shadowhand commented 7 years ago

Yes that syntax looks right. FWIW, there are a few implementations of currying for PHP already. In fact I wrote an implementation a while back that never went anywhere.

pawaclawczyk commented 7 years ago

@shadowhand I've created PR #22 , if you're interested please make code review.

I plan for the future to add type checking at the moment of argument application to curried function, not on the final function call.