Reputation: 15346
Is there a way to use NamedTuple as Generics? Something like:
alias JsonCommand = NamedTuple(T){
name : String
data : T
}
command : JsonCommand(String) = { name: "some command", data: "some data" }
Upvotes: 1
Views: 141
Reputation: 5661
No.
The main reason why named tuples exist in the language is for implementing named arguments.
For every other use case it's recommended to use a struct instead and it can be used with generics.
record JSONCommand(T), name : String, data : T
command = JSONCommand.new(name: "some command", data: "some data")
Upvotes: 2