Dammit!. How'd I miss that?! Thanks Dan. I updated the sample accordingly.

On Fri, Jun 4, 2021, 9:10 PM Dan Kortschak <d...@kortschak.io> wrote:

> On Fri, 2021-06-04 at 20:29 -0700, Deiter wrote:
> > The reflect package provides the SetMapIndex method for updating
> > elements in a map that are represented by a reflect.Value type, but I
> > don’t see an equivalent for array/slice.
> > The sample app (link provided below) includes an example of map
> > that’s been made accessible through a a reflect.Value type variable.
> > One of the elements in the map is updated using SetMapIndex.
> > The sample app also includes an example of a slice containing exactly
> > the same data as the map. As far as I can tell, the only way to
> > update an element of the slice through a reflect.Value type variable
> > is to introduce unsafe package
> > Is there a better way that I’m missing that doesn’t require the use
> > of the unsafe package
> > SetMapIndex() equivalent for slice/array
>
> You can call Set on the reflect.Value returned by Index of a slice or
> array.
>
> slice: https://play.golang.org/p/b1NscgQ7UC5
> array: https://play.golang.org/p/xCAGuTL5Wbl
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP6bC05AtcWHYMj5xpHo-0hChm4YuWFT6d0ANVPky0d7kr8WRA%40mail.gmail.com.

Reply via email to