#How to use two types in one array, without interfaces?

12 messages · Page 1 of 1 (latest)

marble shore
#

you can have the struct type be based on a type parameter, but you cannot arbitrarily have two different types that an element could be

#

do you have an array of objects, with each object containing those two sub-objects?

#

i had assumed from the interfaces part of the question that you meant it’d be one or the other

#

okay, then what exactly is the issue? that’s pretty straightforward, just give each the correct struct tag

#

could you show an example of the data?

#

that might be helpful, i’m having trouble visualizing the shape of the data

#

okay, so it is one type or the other?

marble shore
leaden thunder
#

they all look the same to me if you make the union of what you get (size is missing some times? and owner id some other?)

#

use owner_id to tell the real type? no reflection needed?

#

I mean get a slice of []UnionType out from db first and then split into 2 properly typed slices []File and []Folder - it’s ok your data object is somewhat ugly, it’s transient