From 9717a2679b2ade83be451a5c1cc7c296694c8442 Mon Sep 17 00:00:00 2001 From: Rangel Reale Date: Sun, 22 Oct 2023 08:02:54 -0300 Subject: [PATCH] clone method --- table.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/table.go b/table.go index 161d2ea..54b015e 100644 --- a/table.go +++ b/table.go @@ -13,7 +13,7 @@ type Data struct { Tables map[string]*Table } -// Merge merges source into d. A deep copy is done to ensure source is never modified. +// Merge merges source into the current instance. A deep copy is done to ensure source is never modified. func (d *Data) Merge(source *Data) error { if source.Tables == nil { return nil @@ -38,6 +38,16 @@ func (d *Data) Merge(source *Data) error { return nil } +// Clone creates a deep-copy of the source. The source [Data] is never modified. +func (d *Data) Clone(source *Data) (*Data, error) { + newd := &Data{} + err := newd.Merge(d) + if err != nil { + return nil, err + } + return newd, nil +} + type Table struct { ID string Config TableConfig