In Golang to pass to the function the arrays of structures of different types?

I have a few arrays of structures of different types.
I need to pass in turn these arrays into a function.
But the structures are different.

Code something like this:
Function func(MyStruct /*What to write here?*/){
 for _ , field := range MyStruct {
...
}
}

func main() {
...
 Function(city, country, []MyStruct1)
 Function(city, country, []MyStruct2)
...
}


Is it even possible to implement?
June 27th 19 at 15:22
2 answers
June 27th 19 at 15:24
Don't do that.

It is not necessary to pull in a typed language, which also protects you from your own mistakes- no need to pull the architectural principles of dynamic languages.

Forehead: you can replace the interface iterator is a concrete implementation which will be different for different types, but the signature of the interface will be the same, so it will be easy to pass to the function.

Less to write, but ugly is to pass different types of arrays in different account options
1132 times gochorus funky take a slice of empty interfaces - astrid_Sawayn commented on June 27th 19 at 15:27
:
It is not necessary to do so.
This is a defect of the programmer. - collee commented on June 27th 19 at 15:30
: What is left technical capability - does not mean that this opportunity should always be used.
Interfaces you offer Varina is a potential problem in the program.
If you really like the interface as I use them in the first version posted is the interface that implements the iterator. - collee commented on June 27th 19 at 15:33
: sorry but the type assertion - or the next moaning about the generic (and then sfinae crtp), why not Rast and not Java, etc.
idiomatically iterate through range - interface{} equivalence is a type-safe void* in C. - astrid_Sawayn commented on June 27th 19 at 15:36
:

programming languages - different.
they are different, in particular, and because different languages use different approaches.

necha pull approaches from one language to another.

bare empty interfaces can be used, but not necessary. - collee commented on June 27th 19 at 15:39
: "necha pull approaches from one language to another." you contradict yourself. iterators and in-house containers (a lot from for example C++) instead of relatives, the transfer of different types in different settings (C) instead of type assertion,

I'm not lazy, rsc wrote and his answer was - "Either approach is fine, depending on the circumstances. In general you should write what you feel results in the clearest, most understandable, most maintainable code."

So iterators will be the most difficult, function of the type is easier of course (but what if the criteria of the passage change? necessary to every rule) but still one for the type (a kind of manual to C++ but without templates and then cries about generics), and one funk loop with range + type assertion the most simple. - astrid_Sawayn commented on June 27th 19 at 15:42
:

"Nechayev to draw approaches from one language to another." you contradict yourself. iterators and in-house containers (a lot from for example C++) instead of relatives, the transfer of different types in different settings (C) instead of type assertion

Some parts of one language is absolutely identical to another programming language.
But it can deceive only the inexperienced programmer, a student, like you, who has really never seen programming languages.
And you should not make incorrect generalizations that just because some part of the languages coincide, and in another part they are the same. - collee commented on June 27th 19 at 15:45
: I am very, very, very happy that you have lost the argument on the merits. - astrid_Sawayn commented on June 27th 19 at 15:48
I have already written - how to use alien concepts for language.
If some pieces of programmers don't understand this, I suggest obsudat in five years, when you will have to understand what it was about. - collee commented on June 27th 19 at 15:51
: OK - come back in five when you have at least one decade of product sla withheld - astrid_Sawayn commented on June 27th 19 at 15:54
June 27th 19 at 15:26
[]interface{}
Checked?
https://github.com/golang/go/wiki/InterfaceSlice - astrid_Sawayn commented on June 27th 19 at 15:29
: https://play.golang.org/p/N-2R0RUcNc - collee commented on June 27th 19 at 15:32

Find more questions by tags GoProgramming