PARTIAL APPLICATION
Ron Buckton – Microsoft Corporation
MOTIVATIONS
const add = (x, y) => x + y;
�// Function#bind
const addOne = add.bind(null, 1);
addOne(2); // 3
�// arrow functions
const addTen = x => add(x, 10);
addTen(2); // 12
�// arrow functions and pipeline
const newScore = player.score
|> (_ => add(7, _))
|> (_ => clamp(0, 100, _));
PROPOSAL
// `?` placeholder�f(x, ?) // left apply
f(?, x) // right apply
f(?, x, ?) // middle apply
// `...` rest placeholder�f(x, ...) // left apply
f(..., x) // right apply
f(..., x, ...) // middle apply��// methods�o.f(x, ?)
EXAMPLES
// on its own�const add = (x, y) => x + y;�const addOne = add(?, 1);�[1, 2, 3].map(addOne); // [2, 3, 4]��// argument limiting�[1].forEach(console.log); // 1 0 [1]�[1].forEach(console.log(?)); // 1��// uncurry 'this'�const g = f.call(?, ...);��// add listener�el.addEventListener(this.clicked(?));
// with pipeline, underscore/lodash style�const result = books� |> filter(?, x => x.category === "programming");��// with pipeline, Ramda style�const result = books� |> filter(x => x.category === "programming", ?);
OPEN QUESTIONS
STATUS
EXAMPLES
const countOfBooksByAuthor = library
|> descendantsAndSelf(?)
|> filter(?, node => node.category === "programming")
|> groupBy(?, node => node.author)
|> map(?, group => group |> count(?));
const countOfBooksByAuthor = map(
groupBy(
filter(
descendantsAndSelf(library),
node => node.category === "programming"
),
node => node.author
),
group => count(group)
);