Skip to content

Document subscript[id:] as the preferred id-lookup primitive - #44

Merged
searls merged 1 commit into
mainfrom
docs/looking-up-by-id
May 3, 2026
Merged

Document subscript[id:] as the preferred id-lookup primitive#44
searls merged 1 commit into
mainfrom
docs/looking-up-by-id

Conversation

@bitsly

@bitsly bitsly commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

0.8.0 shipped O(1) subscript[id:] on Catalog, Lens, and GroupedLens (#43), but the rules doc still implies users should hand-write .items.first(where: { \$0.id == id }). Without a mention in the rules file, downstream users naturally reach for the linear-scan idiom — exactly what the PR was designed to obsolete.

This adds a short section to claude/rules/splint.md (between load(_:) vs refresh() and Catalog lifecycle) telling readers:

  • Use catalog[id: id] / lens[id: id] / groupedLens[id: id] — never .items.first(where:).
  • It's O(1).
  • On Lens / GroupedLens, a filtered-out item returns nil (which is almost always what call sites want).
  • Duplicate ids resolve to first-occurrence-wins, matching the prior linear-scan semantics.

Drafted in the voice of the existing sections (rule first, brief why, no code example needed for a trivial subscript surface).

Test plan

  • Doc-only change — no test impact.

🤖 Generated with Claude Code

0.8.0 shipped O(1) subscript[id:] on Catalog, Lens, and GroupedLens,
but the rules doc still implies users should hand-write
.items.first(where: { $0.id == id }). Add a short section between
load/refresh and Catalog lifecycle pointing readers at the new API
and explaining the filter-aware semantics on lenses.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented May 3, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@searls
searls merged commit 80af1e4 into main May 3, 2026
2 checks passed
@searls
searls deleted the docs/looking-up-by-id branch May 3, 2026 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants