winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.04k stars 196 forks source link

Allow keyword arguments to appear anywhere in a call #4812

Open eladb opened 1 year ago

eladb commented 1 year ago

Feature Spec

Keyword arguments are not positional by definition, and there could be stylistic reasons to want to put them before positional arguments.

Consider (beautiful):

new cloud.Function(timeout: 1m, inflight () => {
  log("my function!");
});

Versus (ugly):

new cloud.Function(inflight () => {
  log("my function!");
}, timeout: 1m);

To complement this behavior, I am proposing that we also add a special syntax (I propose to use a spread ...) to denote that a struct needs to be expanded into keyword arguments:

let fn = (pos1: str, pos2: num, opts: ...MyOptions) => { ... }

If the spread is not specified, opts will not expand into keywords.

For practical reasons, When importing JSII functions, we will still automatically assume that the last struct argument is expanded.

Use Cases

Ergonomics and style improvements.

Implementation Notes

No response

Component

Compiler

Community Notes

github-actions[bot] commented 10 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!