1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-11-27 22:08:15 +02:00

Feature/#95 deepclone (#101)

* rename method Clone to Copy

* added Cloneable interface

* added Value to Cloneable interface

* implemented Cloneable intefrace by array

* implemented Cloneable interface by Object

* unit tests for Object.Clone

* move core.IsCloneable to value.go

* change Clone function

* move IsClonable to package values
This commit is contained in:
3timeslazy
2018-10-12 18:58:08 +03:00
committed by Tim Voronov
parent 88188cac2c
commit f91fbf6f8c
19 changed files with 190 additions and 29 deletions

View File

@@ -141,7 +141,7 @@ func (t *Object) Hash() uint64 {
return h.Sum64()
}
func (t *Object) Clone() core.Value {
func (t *Object) Copy() core.Value {
c := NewObject()
for k, v := range t.value {
@@ -202,3 +202,20 @@ func (t *Object) Remove(key String) {
func (t *Object) SetIn(path []core.Value, value core.Value) error {
return SetIn(t, path, value)
}
func (t *Object) Clone() core.Cloneable {
cloned := NewObject()
var value core.Value
var keyString String
for key := range t.value {
keyString = NewString(key)
value, _ = t.Get(keyString)
if IsCloneable(value) {
value = value.(core.Cloneable).Clone()
}
cloned.Set(keyString, value)
}
return cloned
}