I'm trying to decouple algorithm from type. if an algorithm works on a
collection, it ought to work on either a map or slice. It appeared that
result.Value facilitated the decoupling entirely, until I ran into the
limitation with array/slice. It seems odd that I have to use the unsafe the
package with array/slice esp. given the support provided for maps with
SetMapIndex. I figure I must be missing something…

On Fri, Jun 4, 2021 at 8:44 PM Kurtis Rader <kra...@skepticism.us> wrote:

> More context would be useful; i.e., what are you really trying to do and
> why? Such information often allows people to provide better answers;
> including whether this is an example of the [XY Problem](
> https://xyproblem.info/) or you have a misunderstanding how slices work.
> Given your play.golang.org reproducer neither of those responsies seem
> likely but nonetheless...
>
> On Fri, Jun 4, 2021 at 8:29 PM Deiter <hwaterf...@gmail.com> 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
>> <https://play.golang.org/p/X6gsBUW4ME4>
>>
>> --
>> 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/e292b828-4ba9-420d-af2d-8c98fc451ef9n%40googlegroups.com
>> <https://groups.google.com/d/msgid/golang-nuts/e292b828-4ba9-420d-af2d-8c98fc451ef9n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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/CAP6bC04D20ZAXycTGPQ-m2gdT8d3Ya9rG%3D08cUAUvdjswp2Y2g%40mail.gmail.com.

Reply via email to