Skip to content

Partial Application syntax: Stage 1 #9342

@byara

Description

@byara

This proposal introduces a new syntax using the ? token in an argument list which allows you to partially apply an argument list to a call expression by acting as a placeholder for an argument.

Info

Stage: 1
Champion: Ron Buckton (@rbuckton)
Proposal repo: https://github.com/tc39/proposal-partial-application

Example

const addOne = add(1, ?); // apply from the left
addOne(2); // 3

const addTen = add(?, 10); // apply from the right
addTen(2); // 12

// with pipeline
let newScore = player.score
  |> add(7, ?)
  |> clamp(0, 100, ?); // shallow stack, the pipe to `clamp` is the same frame as the pipe to `add`.

// partial template strings
const Diagnostics = {
  unexpected_token: `Unexpected token: ${?}`,
  name_not_found: `'${?}' not found.`
};
Diagnostics.name_not_found("foo"); // "'foo' not found."

Basic Rules

  • can be used one or more at the top level of the Arguments of a CallExpression, CallMemberExpression, or SuperCall (e.g. f(?) or o.f(?))
  • can be used in place of a TemplateMiddleList

ESTree/Parsing

  • I guess we can use the token question
  • we can create a Partial node in parseExprListItem function

Transform

We will add Partial node to the AST and it will be added to the spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions