Skip to content

Commit 51061a4

Browse files
author
Bart Schuurmans
committed
Add Dict.getUnsafe
1 parent 3a45914 commit 51061a4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Core__Dict.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type t<'a> = Js.Dict.t<'a>
22

33
@get_index external get: (t<'a>, string) => option<'a> = ""
4+
@get_index external getUnsafe: (t<'a>, string) => 'a = ""
45
@set_index external set: (t<'a>, string, 'a) => unit = ""
56
@val external delete: 'a => unit = "delete"
67

src/Core__Dict.resi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ switch dict->Dict.get("someKey") {
2424
@get_index
2525
external get: (t<'a>, string) => option<'a> = ""
2626

27+
/**
28+
Returns the value at the provided key.
29+
30+
## Examples
31+
```rescript
32+
let dict = Dict.fromArray([("someKey", "someValue")])
33+
34+
dict->Dict.getUnsafe("someKey") == "someValue"
35+
dict->Dict.getUnsafe("otherKey") // Undefined behaviour
36+
```
37+
38+
## Important
39+
40+
- This is an unsafe operation, it assumes `key` exists in the Dict.
41+
*/
42+
@get_index
43+
external getUnsafe: (t<'a>, string) => 'a = ""
44+
2745
/**
2846
`set(dictionary, key, value)` sets the value at the provided key to the provided value.
2947

0 commit comments

Comments
 (0)