Re: [go-nuts] Re: type assertion: Can I DRY this up?

2016-11-01 Thread wwarner
Ok! I'm looking at this: https://golang.org/src/encoding/json/encode.go On Tuesday, November 1, 2016 at 1:13:31 PM UTC-4, Nathan Fisher wrote: > > I guess it becomes a question of what operations you want to do on the > data. If you look at the implementation of the Json package and sort > inter

[go-nuts] Re: type assertion: Can I DRY this up?

2016-11-01 Thread wwarner
Basically, the idea is: given a json structure, and a list of strings or integers, treat the list as a path into the structure and return the value at that point. There are some things this doesn't do yet, among them: handle float values, handle slice indexes that are out of range, handle paths

[go-nuts] Re: type assertion: Can I DRY this up?

2016-11-01 Thread wwarner
https://play.golang.org/p/LhOTUuTVqA On Tuesday, November 1, 2016 at 12:50:09 PM UTC-4, Bill Warner wrote: > > Yes it's just a fragment. Let me clean it up a bit, then I'll share a > playground link. > > On 11/1/16 12:47 PM, Volker Dobler wrote: > > Am Dienstag, 1. November 2016 02:07:49 UTC+1 sc

Re: [go-nuts] type assertion: Can I DRY this up?

2016-11-01 Thread wwarner
@kortschak I guess I see your point. I can list the types in some code, and attach a Get() method to those. But I'm still going to end up with a big ol' switch statement (or if/else block). Seems to me there should be a way to use reflection to pull this off. Thanks --Bill On Monday, October

[go-nuts] type assertion: Can I DRY this up?

2016-10-31 Thread wwarner
Hello all, I'm new to Go, and I have a question about identifying types as they're encountered in traversing a map[string]interface{}. I've ended up with a big sieve of type assertions something like this: if mt.Mi, ok = m.(map[string]int); ok { nval, ok = mt.Mi[mk]