Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split papp to pal and par (upd.: paL and paR) #2

Open
Alexsey opened this issue Jun 16, 2016 · 3 comments
Open

Split papp to pal and par (upd.: paL and paR) #2

Alexsey opened this issue Jun 16, 2016 · 3 comments

Comments

@Alexsey
Copy link

Alexsey commented Jun 16, 2016

Proposal is to have two functions for partial application: pal and par

pal will partially apply arguments to the left (will work like papp)
par will partially apply arguments to the right

Why 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:

function styleText (text, style) { // this function have typical arguments order
   return style(text)
}

let lines = ['first line', 'second line', 'third line']
let bold = text => `<b>${text}</b>'

let styledLines = lines.map(styleText.par(bold))

Of course if styleText implements data 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 with pal and par partial application would cover such cases whatever API you are using (or supporting. You can't just start to implement data last in existing API with data first tradition)

And also it's easier to pronounce par or pal than papp :)

References:
A few sentences about data last pattern
Most dependent on library for JS Lodash implements it for all their methods in fp build

@gilbert
Copy link
Owner

gilbert commented Jun 16, 2016

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...)

@Alexsey
Copy link
Author

Alexsey commented Jun 16, 2016

At this point we could just mimic existing implementations like Lodash's or Ramda's or any other. This two works well with rest and both output { first: 'x', rest: ['y', 'z', 10, 20] }. I'm also think that it's more consistent with how it would works without rest

This was referenced Jun 17, 2016
@Alexsey
Copy link
Author

Alexsey commented Jul 18, 2016

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

@Alexsey Alexsey changed the title Split papp to pal and par Split papp to pal and par (upd.: paL and paR) Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants