Semantic Diff

#8926 Add getWithDefault and getOrThrow to Belt.HashMap

1 commit, rendered from its record.

Summary

RangeCommitsChangelogAreasJS output changesFormatsFailed checks
58da277de4eeba0d27f17c8056fd4c192e7b7ad9..pr-89261๐Ÿš€ New featureruntimetests1none0

Changelog draft

๐Ÿš€ New feature
  • Add getWithDefault and getOrThrow to Belt.HashMap, Belt.HashMap.Int and Belt.HashMap.String.

58da277de4eeba0d27f17c8056fd4c192e7b7ad9..pr-8926

1e7faef13 ยท Christoph Knittel ยท Oct 19, 2026

Add getWithDefault and getOrThrow to Belt.HashMap

๐Ÿš€ New featureruntimetests

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.

Example ReScript

let m = Belt.HashMap.Int.fromArray([(1, "a")])m->Belt.HashMap.Int.getWithDefault(2, "z") == "z"m->Belt.HashMap.Int.getOrThrow(1) == "a"
๐Ÿš€ New featureAdd getWithDefault and getOrThrow to Belt.HashMap, Belt.HashMap.Int and Belt.HashMap.String.

Review

Output
changedtests/belt_tests/src/belt_hashmap_test.mjs (new tests); no existing program compiles differently
Tests
other~ tests/belt_tests/src/belt_hashmap_test.res plus docstring examples in Belt_HashMap.resi, Belt_HashMapInt.resi, Belt_HashMapString.resi
9 files ยท +313 โˆ’0 ยท changelog 1 ยท other 6 ยท tests 2
Achanges/belt-hashmap-get-with-default.feature.md+1โˆ’0
Mpackages/@rescript/belt/src/Belt_HashMap.res+34โˆ’0
Mpackages/@rescript/belt/src/Belt_HashMap.resi+46โˆ’0
Mpackages/@rescript/belt/src/Belt_HashMapInt.res+34โˆ’0
Mpackages/@rescript/belt/src/Belt_HashMapInt.resi+32โˆ’0
Mpackages/@rescript/belt/src/Belt_HashMapString.res+34โˆ’0
Mpackages/@rescript/belt/src/Belt_HashMapString.resi+32โˆ’0
Mtests/belt_tests/src/belt_hashmap_test.mjs+67โˆ’0
Mtests/belt_tests/src/belt_hashmap_test.res+33โˆ’0
with Claude Opus 5.5