Currently, the signature for Table.Get is func (K) (V, error). This is not very Go-idiomatic, which prefers to return a boolean instead of an error. For instance, a built-in Go map is used like so:
ifvalue,ok:=users[id];!ok{// ...}
Updating our table to look like that is best practice. In that same vein, to support direct lookup (i.e. v := users[id]), this PR also adds Table.Find.
Changes
BREAKING CHANGE: Update contract of Table.Get to func (K) (V, bool). Returns 'false' is the item cannot be found, and 'true' if it is found.
Add Table.Find.
Updated tests and documentation to match the change.
Design Decisions
Chose to make this decision because throwing an error implies that there is something 'wrong' with the table. There is nothing wrong with the table; it is just that the item does not exist.
Checklist
Tests pass
Docs updated
## Description
Currently, the signature for `Table.Get` is `func (K) (V, error)`. This is not very Go-idiomatic, which prefers to return a boolean instead of an error. For instance, a built-in Go map is used like so:
```go
if value, ok := users[id]; !ok {
// ...
}
```
Updating our table to look like that is best practice. In that same vein, to support direct lookup (i.e. `v := users[id]`), this PR also adds `Table.Find`.
## Changes
- BREAKING CHANGE: Update contract of `Table.Get` to `func (K) (V, bool)`. Returns 'false' is the item cannot be found, and 'true' if it is found.
- Add `Table.Find`.
- Updated tests and documentation to match the change.
### Design Decisions
- Chose to make this decision because throwing an error implies that there is something 'wrong' with the table. There is nothing wrong with the table; it is just that the item does not exist.
## Checklist
- [x] Tests pass
- [x] Docs updated
mvhutz
changed title from feat!: update get from (V, error) to (V, bool) to feat!: update get from `(V, error)` to `(V, bool)`2026-04-03 19:40:40 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Description
Currently, the signature for
Table.Getisfunc (K) (V, error). This is not very Go-idiomatic, which prefers to return a boolean instead of an error. For instance, a built-in Go map is used like so:Updating our table to look like that is best practice. In that same vein, to support direct lookup (i.e.
v := users[id]), this PR also addsTable.Find.Changes
Table.Gettofunc (K) (V, bool). Returns 'false' is the item cannot be found, and 'true' if it is found.Table.Find.Design Decisions
Checklist
feat!: update get from (V, error) to (V, bool)to feat!: update get from `(V, error)` to `(V, bool)`