cog icon indicating copy to clipboard operation
cog copied to clipboard

Allow variadic arguments

Open spinillos opened this issue 1 year ago • 2 comments

When we have list of a single type (string, integer, etc), we are setting the array as signature. It implies that the function argument needs an array initialisation to make it works, when we could simplify the API changing it for variadic arguments.

Go:

// Signatures

// Before
func Tags(tags []string) {...}

// After
func Tags(tags ...string) {...}

// Usage

// Before
Tags([]string{"tag1", "tag2"})

// After
Tags("tag1", "tag2")

TS:

// Signatures

// Before
tags(tags: string[]) {...}

// After
tags(...tags: string[]) {...}

// Usage

// Before
tags(['tag1', 'tag2'])

// After
tags('tag1', 'tag2')

spinillos avatar Nov 20 '23 13:11 spinillos