Skip to content

Commit 1078cd7

Browse files
author
Antoine Pelisse
committed
Add method to delete items from maps
1 parent 20836a5 commit 1078cd7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

value/value.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ func (m *Map) Set(key string, value Value) {
8484
m.index = nil // Since the append might have reallocated
8585
}
8686

87+
// Delete removes the key from the set.
88+
func (m *Map) Delete(key string) {
89+
items := []Field{}
90+
for i := range m.Items {
91+
if m.Items[i].Name != key {
92+
items = append(items, m.Items[i])
93+
}
94+
}
95+
m.Items = items
96+
m.index = nil // Since the list has changed
97+
}
98+
8799
// StringValue returns s as a scalar string Value.
88100
func StringValue(s string) Value {
89101
s2 := String(s)

0 commit comments

Comments
 (0)