Open Alexsey opened 8 years ago
Thank for your input! I like the idea of a right-side partial application. My first thought is it might get tricky defining how it works with rest parameters. For example:
function example (first, ...rest) {
return { first, rest }
}
var g = example.rPapp(10, 20)
g('x','y','z') //=> ??
Would this return { first: 'x', rest: [10, 20, 'y', 'z'] }
? I would think so myself. It's something worth noting.
(I write rPapp
because par
to me reads par-tial
, which isn't immediately clear it's from the right. But I bikeshed...)
I have think of it again and you are right - par
is really reads like partial
. On the other hand I do think that short name is critical for such method because of potential of usage of partial functions as arguments of another functions. What do you think about paR
and paL
? Also keep in mind that people will start usage of this feature from paL
and 90% of time their time it would also be paL
Proposal is to have two functions for partial application:
pal
andpar
pal
will partially apply arguments to the left (will work likepapp
)par
will partially apply arguments to the rightWhy is it important? Because it makes possible even for functions that does not implement
data last
pattern (most of current JS APIs) to be used like they does. Example:Of course if
styleText
implementsdata last
pattern and would have an argument order with data as the last argument -papp
would be enough. But probably it would have data first. So withpal
andpar
partial application would cover such cases whatever API you are using (or supporting. You can't just start to implementdata last
in existing API with data first tradition)And also it's easier to pronounce
par
orpal
thanpapp
:)References: A few sentences about
data last
pattern Most dependent on library for JSLodash
implements it for all their methods infp
build