Functional Destructuring: Destructure via function calls using new syntax

As mentioned up-thread, I'm currently working on a proposal for a similar feature based on Scala Extractors: Extractor Objects and Extractor Patterns for ECMAScript · GitHub

I have changes to make to better align with pattern matching (such as using Symbol.matcher instead of Symbol.apply), along with some other work to align with an ADT enum proposal, but I hope to present this to plenary later this year.


@rbuckton Thanks! My primary curiosity was the difference in having the "functional wrapper" on the left-hand side key vs. the value on the right side, but I see according to your actual spec, you've switched that to the right-hand side, so it always wraps the value name. Looks great to me!

It also appears this works for multiple and sub-property wrapper functions, is that right?

Foo(Bar(y)) = x; // multiple
X.Foo(y) = x; // sub-property

I really like this API :raised_hands:t3:

Then paired with the &-anywhere idea, would it work like this (below)?

const title = "Some Title";
const base &
      String.prototype.toLowerCase.apply(lower1) &
      (str => str.toLowerCase())(lower2) &
      String.prototype.toUpperCase.apply(upper1) &
      (str => str.toUpperCase())(upper2) = title;

console.log({ base, lower1, lower2, upper1, upper2 });
   ->  {
         base:   "Some Title",
         lower1: "some title",
         lower2: "some title",
         upper1: "SOME TITLE",
         upper2: "SOME TITLE",