Skip to content

Commit 165b17e

Browse files
authoredJun 5, 2024··
feat: upgrade github.com/benbjohnson/immutable (#5488)
* feat: upgrade github.com/benbjohnson/immutable Newer versions of this package were changed to use generics, making them incompatible with the current code. Update to the newest version. This has the nice side effect of reducing the amount of type assertions. * fix: staticcheck
1 parent 32f7947 commit 165b17e

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed
 

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/SAP/go-hdb v0.14.1
1414
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
1515
github.com/apache/arrow/go/v7 v7.0.1
16-
github.com/benbjohnson/immutable v0.3.0
16+
github.com/benbjohnson/immutable v0.4.3
1717
github.com/bonitoo-io/go-sql-bigquery v0.3.4-1.4.0
1818
github.com/c-bata/go-prompt v0.2.2
1919
github.com/cespare/xxhash/v2 v2.2.0

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.10.0 h1:1jh8J+JjYRp+QWKOsaZt7rGUgoyr
161161
github.com/aws/aws-sdk-go-v2/service/sts v1.10.0/go.mod h1:jLKCFqS+1T4i7HDqCP9GM4Uk75YW1cS0o82LdxpMyOE=
162162
github.com/aws/smithy-go v1.9.0 h1:c7FUdEqrQA1/UVKKCNDFQPNKGp4FQg3YW4Ck5SLTG58=
163163
github.com/aws/smithy-go v1.9.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
164-
github.com/benbjohnson/immutable v0.3.0 h1:TVRhuZx2wG9SZ0LRdqlbs9S5BZ6Y24hJEHTCgWHZEIw=
165-
github.com/benbjohnson/immutable v0.3.0/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI=
164+
github.com/benbjohnson/immutable v0.4.3 h1:GYHcksoJ9K6HyAUpGxwZURrbTkXA0Dh4otXGqbhdrjA=
165+
github.com/benbjohnson/immutable v0.4.3/go.mod h1:qJIKKSmdqz1tVzNtst1DZzvaqOU1onk1rc03IeM3Owk=
166166
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
167167
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
168168
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=

‎values/dict.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ func (d emptyDict) Release() {}
131131

132132
type dict struct {
133133
t semantic.MonoType
134-
data *immutable.SortedMap
134+
data *immutable.SortedMap[(Value), (Value)]
135135
}
136136

137137
func (d dict) Get(key, def Value) Value {
138138
if !key.IsNull() {
139139
v, ok := d.data.Get(key)
140140
if ok {
141-
return v.(Value)
141+
return v
142142
}
143143
}
144144
return def
@@ -163,11 +163,11 @@ func (d dict) Remove(key Value) Dictionary {
163163
func (d dict) Range(f func(key, value Value)) {
164164
itr := d.data.Iterator()
165165
for {
166-
key, value := itr.Next()
167-
if key == nil {
166+
key, value, ok := itr.Next()
167+
if !ok {
168168
return
169169
}
170-
f(key.(Value), value.(Value))
170+
f(key, value)
171171
}
172172
}
173173

@@ -241,7 +241,7 @@ func (d dict) Equal(v Value) bool {
241241
equal = false
242242
return
243243
}
244-
equal = value.Equal(v.(Value))
244+
equal = value.Equal(v)
245245
})
246246
return equal
247247
}
@@ -266,52 +266,52 @@ type (
266266
timeComparer struct{}
267267
)
268268

269-
func (c intComparer) Compare(a, b interface{}) int {
270-
if i, j := a.(Value).Int(), b.(Value).Int(); i < j {
269+
func (c intComparer) Compare(a, b Value) int {
270+
if i, j := a.Int(), b.Int(); i < j {
271271
return -1
272272
} else if i > j {
273273
return 1
274274
}
275275
return 0
276276
}
277277

278-
func (c uintComparer) Compare(a, b interface{}) int {
279-
if i, j := a.(Value).UInt(), b.(Value).UInt(); i < j {
278+
func (c uintComparer) Compare(a, b Value) int {
279+
if i, j := a.UInt(), b.UInt(); i < j {
280280
return -1
281281
} else if i > j {
282282
return 1
283283
}
284284
return 0
285285
}
286286

287-
func (c floatComparer) Compare(a, b interface{}) int {
288-
if i, j := a.(Value).Float(), b.(Value).Float(); i < j {
287+
func (c floatComparer) Compare(a, b Value) int {
288+
if i, j := a.Float(), b.Float(); i < j {
289289
return -1
290290
} else if i > j {
291291
return 1
292292
}
293293
return 0
294294
}
295295

296-
func (c stringComparer) Compare(a, b interface{}) int {
297-
if i, j := a.(Value).Str(), b.(Value).Str(); i < j {
296+
func (c stringComparer) Compare(a, b Value) int {
297+
if i, j := a.Str(), b.Str(); i < j {
298298
return -1
299299
} else if i > j {
300300
return 1
301301
}
302302
return 0
303303
}
304304

305-
func (c timeComparer) Compare(a, b interface{}) int {
306-
if i, j := a.(Value).Time(), b.(Value).Time(); i < j {
305+
func (c timeComparer) Compare(a, b Value) int {
306+
if i, j := a.Time(), b.Time(); i < j {
307307
return -1
308308
} else if i > j {
309309
return 1
310310
}
311311
return 0
312312
}
313313

314-
func dictComparer(dictType semantic.MonoType) immutable.Comparer {
314+
func dictComparer(dictType semantic.MonoType) immutable.Comparer[(Value)] {
315315
if dictType.Nature() != semantic.Dictionary {
316316
panic(UnexpectedKind(dictType.Nature(), semantic.Dictionary))
317317
}
@@ -339,7 +339,7 @@ func dictComparer(dictType semantic.MonoType) immutable.Comparer {
339339
func NewDict(dictType semantic.MonoType) Dictionary {
340340
return dict{
341341
t: dictType,
342-
data: immutable.NewSortedMap(
342+
data: immutable.NewSortedMap[(Value), (Value)](
343343
dictComparer(dictType),
344344
),
345345
}
@@ -350,13 +350,13 @@ func NewDict(dictType semantic.MonoType) Dictionary {
350350
// that create new Dictionary values.
351351
type DictionaryBuilder struct {
352352
t semantic.MonoType
353-
b *immutable.SortedMapBuilder
353+
b *immutable.SortedMapBuilder[(Value), (Value)]
354354
}
355355

356356
// NewDictBuilder will create a new DictionaryBuilder for the given
357357
// key type.
358358
func NewDictBuilder(dictType semantic.MonoType) DictionaryBuilder {
359-
builder := immutable.NewSortedMapBuilder(dictComparer(dictType))
359+
builder := immutable.NewSortedMapBuilder[(Value), (Value)](dictComparer(dictType))
360360
return DictionaryBuilder{t: dictType, b: builder}
361361
}
362362

@@ -374,7 +374,7 @@ func (d *DictionaryBuilder) Get(key Value) (Value, bool) {
374374
if !ok {
375375
return nil, false
376376
}
377-
return v.(Value), true
377+
return v, true
378378
}
379379

380380
// Insert will insert a new key/value pair into the Dictionary.

0 commit comments

Comments
 (0)
Please sign in to comment.