Skip to content

Commit 90f2a34

Browse files
committed
Merge branch 'Object.get-documentation' into Object-docs
2 parents 8b7f4cb + b4b3fda commit 90f2a34

File tree

4 files changed

+294
-37
lines changed

4 files changed

+294
-37
lines changed

src/Core__Object.res

+30-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,36 @@ external assignMany: ({..}, array<{..}>) => {..} = "Object.assign"
6565

6666
@val external copy: (@as(json`{}`) _, {..}) => {..} = "Object.assign"
6767

68-
@get_index external get: ({..}, string) => option<'a> = ""
69-
@get_index external getSymbol: ({..}, Core__Symbol.t) => option<'a> = ""
68+
/**
69+
`get` gets the value of a property by name. Returns `None` if the property does not exist or has the value `undefined`. Otherwise returns `Some`, including if the value is `null`.
70+
71+
## Examples
72+
73+
```rescript
74+
{"a": 1}->Object.get("a") // Some(1)
75+
{"a": 1}->Object.get("b") // None
76+
{"a": undefined}->Object.get("a") // None
77+
{"a": null}->Object.get("a") // Some(null)
78+
{"a": 1}->Object.get("toString")->Option.isSome // true
79+
```
80+
*/
81+
@get_index
82+
external get: ({..}, string) => option<'a> = ""
83+
84+
/**
85+
`getSymbol` gets the value of a property by symbol. Returns `None` if the property does not exist or has the value `undefined`. Otherwise returns `Some`, including if the value is `null`.
86+
87+
## Examples
88+
89+
```rescript
90+
let fruit = Symbol.make("fruit")
91+
let x = Object.empty()
92+
x->Object.setSymbol(fruit, "banana")
93+
x->Object.getSymbol(fruit) // Some("banana")
94+
```
95+
*/
96+
@get_index
97+
external getSymbol: ({..}, Core__Symbol.t) => option<'a> = ""
7098
@get_index external getSymbolUnsafe: ({..}, Core__Symbol.t) => 'a = ""
7199

72100
@set_index external set: ({..}, string, 'a) => unit = ""

0 commit comments

Comments
 (0)