We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Map.get
Thank you for filing! Check list:
type key = A | B let dict = Map.fromArray([(A, Some(1)), (B, None)]) assert(dict->Map.get(A) == Some(Some(1))) // as expected assert(dict->Map.get(B) == None) // expected to fail, passes assert(dict->Map.get(B) == Some(None)) // expected to pass, fails
JS's Map returns undefined when the key is not present, and also when the value is undefined.
undefined
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:
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 } } }
Sorry, something went wrong.
You should be able to work around this by using Null.t instead of option.
Null.t
option
yeah, otherwise the get would need a runtime wrapper (like map.has(x) ? Some(map.get(x)) : None)
get
map.has(x) ? Some(map.get(x)) : None
See also rescript-lang/rescript-core#217
No branches or pull requests
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: