Hi all.
Haskel uses @ symbol to bind the value and its components at the same time, in JS it would look this way:
function f(obj@{foo, bar}) { ... }
The above would create 3 bindings - the whole object obj
and properties foo
and bar
In Haskell it improves ergonomics of writing code a lot - if I started with the pattern and then later realised that I need the whole thing, I can just add the name to the front, without moving pattern to another binding, creating unnecessary noise in diff (in some cases in JS code it moves back and forth several times).
It seems simple and trivial, but switching between Haskell and TypeScript this is one thing I miss most in Typescript - having ability to bind objects and their members in one binding is very convenient.
Symbol "@" in JS is probably best reserved for decorators, even if not needed in this context...
Some semantically meaningful options could be "." and "?." to allow binding (and optionally binding) properties and elements in arguments:
function f(obj.{foo, bar}, tuple?.[x, y]) { ... }
What do you think?