Skip to content

Commit 89b399b

Browse files
committed
fix all doc examples
1 parent f3af423 commit 89b399b

21 files changed

+245
-244
lines changed

src/Core__Array.resi

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let make: (~length: int, 'a) => array<'a>
3636
Creates an array of length `length` initialized with the value returned from `f ` for each index.
3737

3838
```res example
39-
Array.make(~length=3, i => i + 3) == [3, 4, 5]
39+
Array.fromInitializer(~length=3, i => i + 3) == [3, 4, 5]
4040
```
4141
*/
4242
let fromInitializer: (~length: int, int => 'a) => array<'a>
@@ -622,8 +622,11 @@ type languages = ReScript | TypeScript | JavaScript
622622

623623
let array = [ReScript, JavaScript]
624624

625-
Console.log(array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript)) // 0
626-
Console.log(array->Array.findIndex((item, index) => index === 0 && item == TypeScript)) // -1
625+
let isReScriptFirst = array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript)
626+
let isTypeScriptFirst = array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript)
627+
628+
Console.log(isReScriptFirst) // 0
629+
Console.log(isTypeScriptFirst) // -1
627630
```
628631
*/
629632
@send
@@ -739,7 +742,7 @@ let reduceRight: (array<'a>, 'b, ('b, 'a) => 'b) => 'b
739742
Like `reduceRight`, but with an additional index argument on the callback function.
740743

741744
```res example
742-
Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i, 0) == 16
745+
Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16
743746
```
744747
*/
745748
let reduceRightWithIndex: (array<'a>, 'b, ('b, 'a, int) => 'b) => 'b
@@ -818,6 +821,7 @@ Use `Array.getUnsafe` only when you are sure the `index` exists (i.e. when using
818821

819822
## Examples
820823
```rescript
824+
let array = [1, 2, 3]
821825
for index in 0 to array->Array.length - 1 {
822826
let value = array->Array.getUnsafe(index)
823827
Console.log(value)
@@ -971,7 +975,7 @@ external flatMap: (array<'a>, 'a => array<'b>) => array<'b> = "flatMap"
971975
Otherwise returns `None`
972976

973977
```res example
974-
Array.findMap([1, 2, 3], n => mod(n, 2) ? Some(n - 2) : None) == 0
978+
Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None) == Some(0) // true
975979
```
976980
*/
977981
let findMap: (array<'a>, 'a => option<'b>) => option<'b>

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: 14 additions & 10 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
@@ -40,7 +40,7 @@ external assert2: (bool, 'a, 'b) => unit = "console.assert"
4040

4141
```rescript
4242
Console.assert3(false, "Hello", "World", "ReScript")
43-
Console.assert3(n == 42, "One", 2, #3)
43+
Console.assert3(42 == 42, "One", 2, #3)
4444
```
4545
*/
4646
@val
@@ -52,8 +52,9 @@ external assert3: (bool, 'a, 'b, 'c) => unit = "console.assert"
5252
## Examples
5353

5454
```rescript
55+
let value = 42
5556
Console.assert4(false, "Hello", "World", "ReScript", "!!!")
56-
Console.assert4(m == 42, [1, 2], (3, 4), [#5, #6], #"polyvar")
57+
Console.assert4(value == 42, [1, 2], (3, 4), [#5, #6], #"polyvar")
5758
```
5859
*/
5960
@val
@@ -65,8 +66,9 @@ external assert4: (bool, 'a, 'b, 'c, 'd) => unit = "console.assert"
6566
## Examples
6667

6768
```rescript
69+
let value = 42
6870
Console.assert5(false, "Hello", "World", "JS", '!', '!')
69-
Console.assert5(n == 42, [1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"})
71+
Console.assert5(value == 42, [1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"})
7072
```
7173
*/
7274
@val
@@ -78,8 +80,9 @@ external assert5: (bool, 'a, 'b, 'c, 'd, 'e) => unit = "console.assert"
7880
## Examples
7981

8082
```rescript
83+
let value = 42
8184
Console.assert6(false, "Hello", "World", "JS", '!', '!', '?')
82-
Console.assert6(n == 42, [1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42)
85+
Console.assert6(value == 42, [1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42)
8386
```
8487
*/
8588
@val
@@ -91,8 +94,9 @@ external assert6: (bool, 'a, 'b, 'c, 'd, 'e, 'f) => unit = "console.assert"
9194
## Examples
9295

9396
```rescript
97+
let value = 42
9498
Console.assertMany(false, ["Hello", "World"])
95-
Console.assertMany(n == 42, [1, 2, 3])
99+
Console.assertMany(value == 42, [1, 2, 3])
96100
```
97101
*/
98102
@val
@@ -249,7 +253,7 @@ on MDN.
249253
## Examples
250254

251255
```rescript
252-
Console.dir({"language": "rescript", "version": 10.1.2})
256+
Console.dir({"language": "rescript", "version": "10.1.2"})
253257
```
254258
*/
255259
@val
@@ -325,7 +329,7 @@ external error4: ('a, 'b, 'c, 'd) => unit = "console.error"
325329
## Examples
326330

327331
```rescript
328-
Console.error5('e', 'r, 'r', 'o', 'r')
332+
Console.error5('e', 'r', 'r', 'o', 'r')
329333
Console.error5(1, #second, #third, ("fourth"), 'c')
330334
```
331335
*/
@@ -597,7 +601,7 @@ on MDN.
597601
## Examples
598602

599603
```rescript
600-
Console.table({"language": "rescript", "version": 10.1.2})
604+
Console.table({"language": "rescript", "version": "10.1.2"})
601605
```
602606
*/
603607
@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__Error.resi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ See [`Error.prototype.stack`](https://developer.mozilla.org/en-US/docs/Web/JavaS
2828

2929
## Example
3030
```rescript
31-
Console.log(someError->Error.stack) // Logs `stack` if it exists on `someError`
31+
let error = Error.make("error")
32+
Console.log(error->Error.stack) // Logs `stack` if it exists on `someError`
3233
```
3334
*/
3435
@get

src/Core__Float.resi

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ See [`parseFloat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
153153
```rescript
154154
Float.parseFloat("1.0") // 1.0
155155
Float.parseFloat(" 3.14 ") // 3.14
156-
Float.parseFloat(3.0) // 3.0
156+
Float.parseFloat("3.0") // 3.0
157157
Float.parseFloat("3.14some non-digit characters") // 3.14
158158
Float.parseFloat("error")->Float.isNaN // true
159159
```
@@ -190,10 +190,10 @@ See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
190190
## Examples
191191

192192
```rescript
193-
Float.parseInt("10.0", ~radix=2) // 2.0
194-
Float.parseInt("15 * 3", ~radix=10) // 15.0
195-
Float.parseInt("12", ~radix=13) // 15.0
196-
Float.parseInt("17", ~radix=40)->Float.isNaN // true
193+
Float.parseIntWithRadix("10.0", ~radix=2) // 2.0
194+
Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0
195+
Float.parseIntWithRadix("12", ~radix=13) // 15.0
196+
Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true
197197
```
198198
*/
199199
@val
@@ -258,8 +258,8 @@ See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
258258
## Examples
259259

260260
```rescript
261-
Float.toFixed(300.0, ~digits=4) // "300.0000"
262-
Float.toFixed(300.0, ~digits=1) // "300.0"
261+
Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000"
262+
Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0"
263263
```
264264

265265
## Exceptions
@@ -286,15 +286,15 @@ Float.toPrecision(1.0) // "1"
286286
external toPrecision: float => string = "toPrecision"
287287

288288
/**
289-
`toPrecision(v, ~digits)` return a `string` representing the giver value with
289+
`toPrecisionWithPrecision(v, ~digits)` return a `string` representing the giver value with
290290
precision. `digits` specifies the number of significant digits.
291291
See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.
292292

293293
## Examples
294294

295295
```rescript
296-
Float.toPrecision(100.0, ~digits=2) // "1.0e+2"
297-
Float.toPrecision(1.0) // "1.0"
296+
Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2"
297+
Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1"
298298
```
299299

300300
## Exceptions
@@ -329,8 +329,8 @@ See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
329329
## Examples
330330

331331
```rescript
332-
Float.toString(6.0, ~radix=2) // "110"
333-
Float.toString(3735928559.0, ~radix=16) // "deadbeef"
332+
Float.toStringWithRadix(6.0, ~radix=2) // "110"
333+
Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef"
334334
Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c"
335335
```
336336

@@ -350,10 +350,10 @@ See [`Number.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaS
350350

351351
```rescript
352352
// If the application uses English as the default language
353-
Int.toLocaleString(1000.0) // "1,000"
353+
Float.toLocaleString(1000.0) // "1,000"
354354

355355
// If the application uses Portuguese Brazil as the default language
356-
Int.toLocaleString(1000.0) // "1.000"
356+
Float.toLocaleString(1000.0) // "1.000"
357357
```
358358
*/
359359
@send
@@ -404,7 +404,7 @@ external fromInt: int => float = "%identity"
404404
## Examples
405405

406406
```rescript
407-
Int.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"
@@ -417,10 +417,10 @@ if `max` < `min` returns `min`.
417417
## Examples
418418

419419
```rescript
420-
Int.clamp(4.2) == 4.2
421-
Int.clamp(4.2, ~min=4.3) == 4.3
422-
Int.clamp(4.2, ~max=4.1) == 4.1
423-
Int.clamp(4.2, ~min=4.3, ~max=4.1) == 4.3
420+
Float.clamp(4.2) == 4.2
421+
Float.clamp(4.2, ~min=4.3) == 4.3
422+
Float.clamp(4.2, ~max=4.1) == 4.1
423+
Float.clamp(4.2, ~min=4.3, ~max=4.1) == 4.3
424424
```
425425
*/
426426
let clamp: (~min: float=?, ~max: float=?, float) => float

0 commit comments

Comments
 (0)