Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Created December 2, 2009 17:19
Show Gist options
  • Save rrichardson/247357 to your computer and use it in GitHub Desktop.
Save rrichardson/247357 to your computer and use it in GitHub Desktop.
type Cloneable interface {
Clone() Cloneable;
}
type MapA map[int]string;
type MapB map[string]int;
func (m MapA) Clone() Clonable {
nmap := make(MapA);
for k,v := range(m) {
nmap[k] = v;
}
return nmap;
}
func (m MapB) Clone() Cloneable {
nmap := make(MapB);
for k,v := range(m) {
nmap[k] = v;
}
return nmap;
}
func main() {
m1 := make(MapA);
m1[1] = "foo";
//var m2 MapB;
c := m1.Clone();
fmt.Println(c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment