You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a way to handle lists of generics with unbounded size:
functionidentity<...T>(array: T){// ...}
Which would be equivalent to:
declarefunctionidentity2<A,B>(items:[A,B]): [A,B];declarefunctionidentity2<A,B,C>(items:[A,B,C]): [A,B,C];// with infinitely many signaturesfunctionidentity<T>(items:T): T {returnitems;}
That would for example be useful to type a reverse function. That function would take an arbitrary number of arguments and return them in reverse order: reverse(1, 2, "3") = ["3", 2, 1]. For now it seems that this is only possible by having a fixed length for the input, or by declaring several signatures, one for each possible number of arguments.
A more concrete use case I have is with this zip function, which for now only takes 2, 3 or 4 iterables as parameter:
Proposal
Adding a way to handle lists of generics with unbounded size:
Which would be equivalent to:
Test it here.
Use case
That would for example be useful to type a
reverse
function. That function would take an arbitrary number of arguments and return them in reverse order:reverse(1, 2, "3") = ["3", 2, 1]
. For now it seems that this is only possible by having a fixed length for the input, or by declaring several signatures, one for each possible number of arguments.A more concrete use case I have is with this zip function, which for now only takes 2, 3 or 4 iterables as parameter:
The text was updated successfully, but these errors were encountered: