How to assign two slices containing different types? #38
-
For example:
generates:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You want to generate a function that converts all from objects
There are multiple interpretations of the request to assign a slice of one type to a slice of another type.
Implementing a solution to any interpretation requires use of type conversion or assertion. Implementationv0.4Use the converttype Copygen interface {
ToCurrenciesContract(m []*models.Currency) []*contracts.Currency
}
/* Define the function and field this converter is applied to using regex. */
// convert .* \[\]\*models.Currency
// ModelCurrenciesToContractCurrencies converts a slice of model currencies to a slice of contract currencies.
func ModelCurrenciesToContractCurrencies(m []*models.Currency) []*contracts.Currency{
var output []*contracts.Currency
// Your implementation according to the interpretation above goes here...
return output
} Need more information on the This should generate the following code. // ToCurrenciesContract copies a []*models.Currency to a []*contracts.Currency.
func ToCurrenciesContract(tc []*contracts.Currency, fm []*models.Currency) {
// []*contracts.Currency fields
tc = ModelCurrenciesToContractCurrencies(fm)
} If not, please report this problem in the issue tracker. v0.5Use the castComing soon. |
Beta Was this translation helpful? Give feedback.
You want to generate a function that converts all from objects
[]*models.Currency
to[]*contracts.Currency
.[]*models.Currency
is a slice of struct pointers to amodels.Currency
struct.[]*contracts.Currency
is a slice of struct pointers to acontracts.Currency
struct.There are multiple interpretations of the request to assign a slice of one type to a slice of another type.
contracts.Currency
tomodels.Currency
.contracts.Currency
tomodels.Currency
object (using type conversion).