Skip to content

Commit

Permalink
clone method
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale committed Oct 22, 2023
1 parent c80a799 commit 9717a26
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9717a26

Please sign in to comment.