gpt4 book ai didi

go - 在没有泛型的情况下在Golang中重用类似的代码

转载 作者:行者123 更新时间:2023-12-01 21:18:25 25 4
gpt4 key购买 nike

鉴于我有一个类型的MyMap变量

*map[uuid.UUID][]*Thing

和一段这样的代码:
h.MyMap[id] = append(h.MyMap[id], &thingA)

// other stuff with MyMap like this, later:

h.MyMapp[id][k] = &thingB

// and so on... the actual code is way more complex

和上面相同的代码,除了它使用类型的映射:
*map[int64][]*Thing

是否有Golang可以将其干燥并编写在一个地方做类似代码的助手?

谢谢你。

最佳答案

[I]s there a Golang way to DRY it and write a helper that does the similar code in one place?



不。

关于go - 在没有泛型的情况下在Golang中重用类似的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60948567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com