Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Anything ¶
func Anything(x interface{}) (interface{}, error)
Anything makes a deep copy of whatever gets passed in. It handles pretty much all known Go types (with the exception of channels, unsafe pointers, and functions). Note that this is a truly deep copy that will work it's way all the way to the leaves of the types--any pointer will be copied, any values in any slice or map will be deep copied, etc. Note: in order to avoid an infinite loop, we keep track of any pointers that we've run across. If we run into that pointer again, we don't make another deep copy of it; we just replace it with the copy we've already made. This also ensures that the cloned result is functionally equivalent to the original value.
Example ¶
tests := []interface{}{ `"Now cut that out!"`, 39, true, false, 2.14, []string{ "Phil Harris", "Rochester van Jones", "Mary Livingstone", "Dennis Day", }, [2]string{ "Jell-O", "Grape-Nuts", }, } for _, expected := range tests { actual := MustAnything(expected) fmt.Println(actual) }
Output: "Now cut that out!" 39 true false 2.14 [Phil Harris Rochester van Jones Mary Livingstone Dennis Day] [Jell-O Grape-Nuts]
func MustAnything ¶
func MustAnything(x interface{}) interface{}
MustAnything does a deep copy and panics on any errors.
Types ¶
This section is empty.