-
Notifications
You must be signed in to change notification settings - Fork 469
Core Map.get
when map has with optional values
#7054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Good catch. I think it's an issue of the Core binding It actually need runtime to handle nested option correctly module Map = {
include Map
let get = (t, key) => {
if t->has(key) {
Some(t->get(key)->Option.getUnsafe)
} else {
None
}
}
}
|
You should be able to work around this by using |
yeah, otherwise the |
See also rescript-lang/rescript-core#217 |
But the question is if we should get rid of nested options altogether? See #7430. |
Hmm, actually not, it will emit code like let v = m.get("A");
let v$1 = v === undefined ? undefined : Primitive_option.some(v); which does not really help us distinguish between the value being absent and the value being present, but undefined. |
Thank you for filing! Check list:
JS's Map returns
undefined
when the key is not present, and also when the value isundefined
.https://github.com/rescript-lang/experimental-rescript-stdlib-build/blob/aa8001a778a8975f83ece0a5266b3049b9d20d42/core/src/Core__Map.res#L14
Apologies if issue is in the wrong place, I am new to rescript
The text was updated successfully, but these errors were encountered: