///|
test "update a retry context without changing its baseline snapshot" {
let request_id : @any_collection.AnyRef[String, String] = @any_collection.AnyRef::AnyRef(
"request_id",
)
let retry_count : @any_collection.AnyRef[String, Int32] = @any_collection.AnyRef::AnyRef(
"retry_count",
)
let live_context = @any_collection.AnyMutableMap::AnyMutableMap([])
live_context.set(request_id, "req-42")
live_context.set(retry_count, 0)
live_context.set(retry_count, live_context.get_or(retry_count, 0) + 1)
let baseline = @any_collection.AnyImmutableHashMap::AnyImmutableHashMap([
request_id.entry("req-42"),
retry_count.entry(0),
])
let retry_snapshot = baseline.added(
retry_count,
live_context.get_or(retry_count, 0),
)
inspect(live_context.get_or(request_id, ""), content="req-42")
inspect(live_context.get_or(retry_count, 0), content="1")
inspect(baseline.get_or(retry_count, 0), content="0")
inspect(retry_snapshot.get_or(retry_count, 0), content="1")
}fn[K : Hash + Eq] AnyImmutableHashMap::AnyImmutableHashMap(entries : ArrayView[(K, Any)]) -> AnyImmutableHashMap[K]fn[K : Hash + Eq, T] AnyImmutableHashMap::added(self : AnyImmutableHashMap[K], reference : AnyRef[K, T], value : T) -> AnyImmutableHashMap[K]fn[K : Hash + Eq, T] AnyImmutableHashMap::get(self : AnyImmutableHashMap[K], reference : AnyRef[K, T]) -> T? raisefn[K : Hash + Eq, T] AnyImmutableHashMap::get_or(self : AnyImmutableHashMap[K], reference : AnyRef[K, T], default : T) -> Tfn[K : Hash + Eq, T] AnyImmutableHashMap::get_or_none(self : AnyImmutableHashMap[K], reference : AnyRef[K, T]) -> T?fn[K : Hash + Eq] AnyMutableMap::AnyMutableMap(entries : ArrayView[(K, Any)], capacity? : Int) -> AnyMutableMap[K]fn[K : Hash + Eq, T] AnyMutableMap::get(self : AnyMutableMap[K], reference : AnyRef[K, T]) -> T? raisefn[K : Hash + Eq, T] AnyMutableMap::get_or(self : AnyMutableMap[K], reference : AnyRef[K, T], default : T) -> Tfn[K : Hash + Eq, T] AnyMutableMap::get_or_none(self : AnyMutableMap[K], reference : AnyRef[K, T]) -> T?fn[K : Hash + Eq, T] AnyMutableMap::set(self : AnyMutableMap[K], reference : AnyRef[K, T], value : T) -> Unitpub struct AnyRef[K, T] {
key : K
// private fields
}Install
Download zipFocused utility collections, traits, and value types for MoonBit