feat!: update get from (V, error) to (V, bool) #20

Merged
mvhutz merged 3 commits from feat/get-no-error into main 2026-04-14 01:58:16 +00:00
Showing only changes of commit 81ce24e7b7 - Show all commits

View File

@@ -95,7 +95,8 @@ func (t *Table[K, V]) shrink() error {
return t.resize(t.bucketA.capacity / t.growthFactor)
}
// Get fetches the value for a key in the [Table].
// Get fetches the value for a key in the [Table]. Matches the comma-ok pattern
// of a builtin map; see [Table.Find] for plain indexing.
func (t Table[K, V]) Get(key K) (value V, ok bool) {
if item, ok := t.bucketA.get(key); ok {
return item, true
@@ -108,6 +109,13 @@ func (t Table[K, V]) Get(key K) (value V, ok bool) {
return
}
// Find fetches the value of a key. Matches direct indexing of a builtin map;
// see [Table.Get] for a comma-ok pattern.
func (t Table[K, V]) Find(key K) (value V) {
value, _ = t.Get(key)
return
}
// Has returns true if a key has a value in the table.
func (t Table[K, V]) Has(key K) (exists bool) {
_, exists = t.Get(key)