Hello,
I have a stream of events, each event has a type field as string and data.
I'm a Go programmer, and Im using reflection / interfaces{} to parse the events into correct type.
How would you do it in Nim. In Go basically I have map of strings and type of event, and use reflection to parse into correct type.
Also I do a case on type of event.
Regards
Thanks, that works..Also what I normally use in Golang is :
switch v := i.(type) {
case int:
fmt.Printf("Twice %v is %v\n", v, v*2)
case string:
fmt.Printf("%q is %v bytes long\n", v, len(v))
default:
fmt.Printf("I don't know about type %T!\n", v)
}
Also, Should I use templates for this?.. I have quite big case statments sometimes.
I don't know your use case, but if I have to guess, you don't have to.
If you only need a field or two, you can just retrieve the fields you need.