Skip to content

Commit 9a3cf5e

Browse files
committed
fix docstrings examples - part 2
1 parent 7fe04fb commit 9a3cf5e

12 files changed

+44
-54
lines changed

src/Core__AsyncIterator.resi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ See [async iterator protocols](https://developer.mozilla.org/en-US/docs/Web/Java
2929
## Examples
3030
- A simple example, getting the next value:
3131
```rescript
32-
let {done, value} = await someAsyncIterator->AsyncIterator.next
32+
@val external asyncIterator: AsyncIterator.t<int> = "someAsyncIterator"
33+
let {AsyncIterator.done, value} = await asyncIterator->AsyncIterator.next
3334
```
3435
3536
- Complete example, including looping over all values:

src/Core__Console.resi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on MDN.
1414
1515
```rescript
1616
Console.assert_(false, "Hello World!")
17-
Console.assert_(n == 42, "The answer")
17+
Console.assert_(42 == 42, "The answer")
1818
```
1919
*/
2020
@val
@@ -27,7 +27,7 @@ external assert_: (bool, 'a) => unit = "console.assert"
2727
2828
```rescript
2929
Console.assert2(false, "Hello", "World")
30-
Console.assert2(n == 42, [1, 2, 3], '4')
30+
Console.assert2(42 == 42, [1, 2, 3], '4')
3131
```
3232
*/
3333
@val

src/Core__Date.resi

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,15 @@ You can use the result like any valid date, but many functions like `toString` w
6767
6868
## Examples
6969
```rescript
70-
Date.fromString("2023")
71-
// 2023-01-01T00:00:00.000Z
70+
Date.fromString("2023") // 2023-01-01T00:00:00.000Z
7271
73-
Date.fromString("2023-02-20")
74-
// 2023-02-20T00:00:00.000Z
72+
Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z
7573
76-
Date.fromString("2023-02-20T16:40:00.00Z")
77-
// 2023-02-20T16:40:00.000Z
74+
Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z
7875
79-
Date.fromString("")
80-
// Invalid Date
76+
Date.fromString("") // Invalid Date
8177
82-
Date.fromString("")->getTime
83-
// NaN
78+
Date.fromString("")->Date.getTime // NaN
8479
```
8580
*/
8681
@new
@@ -801,8 +796,7 @@ Returns the year of a given date (according to UTC time).
801796
802797
## Examples
803798
```rescript
804-
Date.fromString("2023-01-01T00:00:00.00+01:00").getUTCFullYear
805-
// 2022
799+
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022
806800
```
807801
*/
808802
@send
@@ -815,8 +809,7 @@ Returns the month of a given date (according to UTC time).
815809
816810
## Examples
817811
```rescript
818-
Date.fromString("2023-01-01T00:00:00.00+01:00").getUTCMonth
819-
// 11
812+
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11
820813
```
821814
*/
822815
@send
@@ -829,8 +822,7 @@ Returns the date (day of month) of a given date (according to UTC time).
829822
830823
## Examples
831824
```rescript
832-
Date.fromString("2023-01-01T00:00:00.00+01:00").getUTCDate
833-
// 31
825+
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31
834826
```
835827
*/
836828
@send
@@ -843,8 +835,7 @@ Returns the hours of a given date (according to UTC time).
843835
844836
## Examples
845837
```rescript
846-
Date.fromString("2023-01-01T00:00:00.00+01:00").getUTCHours
847-
// 23
838+
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23
848839
```
849840
*/
850841
@send
@@ -857,8 +848,7 @@ Returns the minutes of a given date (according to UTC time).
857848
858849
## Examples
859850
```rescript
860-
Date.fromString("2023-01-01T00:00:00.00+01:00").getUTCMinutes
861-
// 0
851+
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0
862852
```
863853
*/
864854
@send
@@ -871,8 +861,7 @@ Returns the seconds of a given date (according to UTC time).
871861
872862
## Examples
873863
```rescript
874-
Date.fromString("2023-01-01T00:00:00.00+01:00").getUTCSeconds
875-
// 0
864+
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0
876865
```
877866
*/
878867
@send
@@ -885,8 +874,7 @@ Returns the milliseconds of a given date (according to UTC time).
885874
886875
## Examples
887876
```rescript
888-
Date.fromString("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds
889-
// 0
877+
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0
890878
```
891879
*/
892880
@send
@@ -900,8 +888,7 @@ Returns the day (day of week) of a given date (according to UTC time).
900888
901889
## Examples
902890
```rescript
903-
Date.fromString("2023-01-01T00:00:00.00+01:00").getUTCDay
904-
// 6
891+
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6
905892
```
906893
*/
907894
@send

src/Core__Dict.resi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ Use `Dict.getUnsafe` only when you are sure the key exists (i.e. when iterating
1717
1818
## Examples
1919
```rescript
20-
let keys = dict->Dict.keys
21-
keys->Array.forEach(key => {
22-
let value = dict->Dict.getUnsafe(key)
23-
Console.log(value)
24-
})
20+
let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")])
21+
let value = dict->Dict.getUnsafe("key1")
22+
Console.log(value) // value1
2523
```
2624
*/
2725
@get_index

src/Core__Float.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ external fromInt: int => float = "%identity"
404404
## Examples
405405
406406
```rescript
407-
Float.mod(7.0, 4.0) == 3
407+
Float.mod(7.0, 4.0) == 3.0
408408
```
409409
*/
410410
external mod: (float, float) => float = "?fmod_float"

src/Core__Int.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ precision. `digits` specifies the number of significant digits. See [`Number.toP
155155
156156
```rescript
157157
Int.toPrecisionWithPrecision(100, ~digits=2) // "1.0e+2"
158-
Int.toPrecisionWithPrecision(1) // "1.0"
158+
Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0"
159159
```
160160
161161
## Exceptions

src/Core__Iterator.resi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ See [iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript
3030
3131
## Examples
3232
```rescript
33+
@val external someIterator: Iterator.t<int> = "someIterator"
3334
// Pulls out the next value of the iterator
34-
let {done, value} = someIterator->Iterator.next
35+
let {Iterator.done, value} = someIterator->Iterator.next
3536
```
3637
*/
3738
@send

src/Core__Map.resi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ Clears all entries in the map.
8989
let map = Map.make()
9090
9191
map->Map.set("someKey", "someValue")
92-
let size = map->Map.size // 1
92+
map->Map.size // 1
9393
9494
map->Map.clear
95-
let size = map->Map.size // 0
95+
map->Map.size // 0
9696
```
9797
*/
9898
@send

src/Core__Null.resi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ Null.getOr(Null.null, "Banana") // Banana
9090
Null.getOr(Null.make("Apple"), "Banana") // Apple
9191
9292
let greet = (firstName: option<string>) =>
93-
"Greetings " ++ firstName->Null.getOr("Anonymous")
93+
"Greetings " ++ firstName->Option.getOr("Anonymous")
9494
95-
Null.make("Jane")->greet // "Greetings Jane"
96-
null->greet // "Greetings Anonymous"
95+
Null.make("Jane")->Null.toOption->greet // "Greetings Jane"
96+
Null.null->Null.toOption->greet // "Greetings Anonymous"
9797
```
9898
*/
9999
let getOr: (t<'a>, 'a) => 'a

src/Core__Nullable.resi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ otherwise return `default`.
9898
9999
```rescript
100100
Nullable.getOr(Nullable.null, "Banana") // Banana
101-
Nullable.getOr(Nulalble.make("Apple"), "Banana") // Apple
101+
Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple
102102
103103
let greet = (firstName: option<string>) =>
104-
"Greetings " ++ firstName->Nullable.getOr("Anonymous")
104+
"Greetings " ++ firstName->Option.getOr("Anonymous")
105105
106-
Nullable.make("Jane")->greet // "Greetings Jane"
107-
Nullable.null->greet // "Greetings Anonymous"
106+
Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane"
107+
Nullable.null->Nullable.toOption->greet // "Greetings Anonymous"
108108
```
109109
*/
110110
let getOr: (t<'a>, 'a) => 'a

src/Core__Object.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ external keysToArray: {..} => array<string> = "Object.keys"
165165
166166
```rescript
167167
let point = {"x": 1, "y": 2}
168-
{"a": 1}->hasOwnProperty("a") // true
169-
{"a": 1}->hasOwnProperty("b") // false
170-
{"a": 1}->hasOwnProperty("toString") // false
168+
{"a": 1}->Object.hasOwnProperty("a") // true
169+
{"a": 1}->Object.hasOwnProperty("b") // false
170+
{"a": 1}->Object.hasOwnProperty("toString") // false
171171
```
172172
*/
173173
@val

src/Core__Promise.resi

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Promise.make((resolve, reject) => {
6565
->then(str => {
6666
Console.log(str)->resolve
6767
})
68-
->catch(e => {
68+
->catch(_ => {
6969
Console.log("Error occurred")
7070
resolve()
7171
})
@@ -127,7 +127,8 @@ See [`Promise.then`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref
127127
## Examples
128128
129129
```rescript
130-
Promise.resolve(5)
130+
open Promise
131+
resolve(5)
131132
->then(num => {
132133
resolve(num + 5)
133134
})
@@ -149,6 +150,7 @@ within the provided callback (e.g. `thenResolve(value => resolve(value))`).
149150
## Examples
150151
151152
```rescript
153+
open Promise
152154
resolve("Anna")
153155
->thenResolve(str => {
154156
"Hello " ++ str
@@ -173,12 +175,13 @@ it originally received. See [`Promise.finally`](https://developer.mozilla.org/en
173175
## Examples
174176
175177
```rescript
178+
open Promise
176179
exception SomeError(string)
177180
let isDone = ref(false)
178181
179182
resolve(5)
180183
->then(_ => {
181-
reject(TestError("test"))
184+
reject(SomeError("test"))
182185
})
183186
->then(v => {
184187
Console.log2("final result", v)
@@ -211,8 +214,8 @@ external finally: (t<'a>, unit => unit) => t<'a> = "finally"
211214
open Promise
212215
let racer = (ms, name) => {
213216
Promise.make((resolve, _) => {
214-
Global.setTimeout(() => {
215-
resolve(. name)
217+
setTimeout(() => {
218+
resolve(name)
216219
}, ms)->ignore
217220
})
218221
}

0 commit comments

Comments
 (0)