From 81ce24e7b7597e7f06de3b8a2b011e47a99f3a58 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Mon, 13 Apr 2026 21:54:29 -0400 Subject: [PATCH] feat: Table.Find --- table.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/table.go b/table.go index 3d3a61a..8b4967d 100644 --- a/table.go +++ b/table.go @@ -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)