Repository navigation
Conversation
Changelog🚀 New Feature
Semantic Diff1 commit · Full page ✏️ Add getWithDefault and getOrThrow to Belt.HashMap43bce48 · cknitt + Claude · Oct 19, 2026, 19:55 UTC · edited Belt.HashMap, Belt.HashMap.Int and Belt.HashMap.String gain getWithDefault and getOrThrow, the same lookups Belt.Map and Belt.MutableMap already have. They walk the bucket directly, so a hit allocates no option; getOrThrow throws Not_found like the other Belt maps. let m = Belt.HashMap.Int.fromArray([(1, "a")])
m->Belt.HashMap.Int.getWithDefault(2, "z") == "z"
m->Belt.HashMap.Int.getOrThrow(1) == "a"Review
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-8926 |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Belt.HashMap, Belt.HashMap.Int and Belt.HashMap.String gain
getWithDefault and getOrThrow, the same lookups Belt.Map and
Belt.MutableMap already have. They walk the bucket directly, so a hit
allocates no option; getOrThrow throws Not_found like the other Belt
maps.
let m = Belt.HashMap.Int.fromArray([(1, "a")])
m->Belt.HashMap.Int.getWithDefault(2, "z") == "z"
m->Belt.HashMap.Int.getOrThrow(1) == "a"
Review: Why getWithDefault and not getOr, as the issue title says? Belt
names this lookup getWithDefault everywhere (Option, Map, MutableMap
and their Int/String variants) and has no getOr; the new functions
follow Belt. getOrThrow is the name Belt already uses, without a
deprecated getExn alias for a new API.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
1e7faef to
43bce48
Compare
Adds
getWithDefaultandgetOrThrowtoBelt.HashMap,Belt.HashMap.IntandBelt.HashMap.String. They walk the bucket directly (no option allocated) andgetOrThrowthrowsNot_found, like the other Belt maps.The issue asks for
getOr; Belt names this lookupgetWithDefaulteverywhere (Option, Map, MutableMap) and has nogetOr, so the new function follows Belt.Fixes #8381.
New tests: mocha cases in
tests/belt_tests/src/belt_hashmap_test.res(generic map, a map whose keys all collide into one bucket, Int and String variants) and docstring examples for each new function.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo