@babel/plugin-proposal-partial-application

Example

(examples are from proposal)

  1. function add(x, y) { return x + y; }
  2. const addOne = add(1, ?); // apply from the left
  3. addOne(2); // 3
  4. const addTen = add(?, 10); // apply from the right
  5. addTen(2); // 12
  6. let newScore = player.score
  7. |> add(7, ?)
  8. |> clamp(0, 100, ?); // shallow stack, the pipe to `clamp` is the same frame as the pipe to `add`.

Valid Usage

  1. f(x, ?) // partial application from left
  2. f(?, x) // partial application from right
  3. f(?, x, ?) // partial application for any arg
  4. o.f(x, ?) // partial application from left
  5. o.f(?, x) // partial application from right
  6. o.f(?, x, ?) // partial application for any arg
  7. super.f(?) // partial application allowed for call on |SuperProperty|

Invalid Usage

  1. f(x + ?) // `?` not in top-level Arguments of call
  2. x + ? // `?` not in top-level Arguments of call
  3. ?.f() // `?` not in top-level Arguments of call
  4. new f(?) // `?` not supported in `new`
  5. super(?) // `?` not supported in |SuperCall|

Installation

  1. $ npm install --save-dev @babel/plugin-proposal-partial-application

Usage

  1. {
  2. "plugins": ["@babel/plugin-proposal-partial-application"]
  3. }

Via CLI

  1. babel --plugins @babel/plugin-proposal-partial-application script.js

Via Node API

  1. require("@babel/core").transformSync("code", {
  2. plugins: ["@babel/plugin-proposal-partial-application"],
  3. });

References