Updated sample <https://play.golang.org/p/o9e6Q3EvemH>

On Sat, Jun 5, 2021 at 6:27 AM Howard Waterfall <hwaterf...@gmail.com>
wrote:

> 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/CAP6bC07m_fgpki-ECzGG%2Bpgw2Ryx%2BLab1QBGj_%2BT3H%2BdhVJ6sA%40mail.gmail.com.

Reply via email to