Skip to content

Commit da72a1b

Browse files
committed
fix last remaining format issues in runtime docstrings
1 parent 6a6347a commit da72a1b

File tree

6 files changed

+39
-88
lines changed

6 files changed

+39
-88
lines changed

runtime/Belt.res

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,15 @@ let letters = ["a", "b", "c"]
130130
let a = letters[0]
131131
132132
// Use a switch statement:
133-
let capitalA =
134-
switch a {
135-
| Some(a) => Some(Js.String.toUpperCase(a))
136-
| None => None
137-
}
133+
let capitalA = switch a {
134+
| Some(a) => Some(Js.String.toUpperCase(a))
135+
| None => None
136+
}
138137
139138
let k = letters[10] // k == None
140139
```
141140
142-
With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors!
141+
With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors\!
143142
144143
### A Special Encoding for Collection Safety
145144
@@ -150,31 +149,25 @@ We use a phantom type to solve the problem:
150149
## Examples
151150
152151
```rescript
153-
module Comparable1 =
154-
Belt.Id.MakeComparable(
155-
{
156-
type t = (int, int)
157-
let cmp = ((a0, a1), (b0, b1)) =>
158-
switch Pervasives.compare(a0, b0) {
159-
| 0 => Pervasives.compare(a1, b1)
160-
| c => c
161-
}
152+
module Comparable1 = Belt.Id.MakeComparable({
153+
type t = (int, int)
154+
let cmp = ((a0, a1), (b0, b1)) =>
155+
switch Pervasives.compare(a0, b0) {
156+
| 0 => Pervasives.compare(a1, b1)
157+
| c => c
162158
}
163-
)
159+
})
164160
165161
let mySet1 = Belt.Set.make(~id=module(Comparable1))
166162
167-
module Comparable2 =
168-
Belt.Id.MakeComparable(
169-
{
170-
type t = (int, int)
171-
let cmp = ((a0, a1), (b0, b1)) =>
172-
switch Pervasives.compare(a0, b0) {
173-
| 0 => Pervasives.compare(a1, b1)
174-
| c => c
175-
}
163+
module Comparable2 = Belt.Id.MakeComparable({
164+
type t = (int, int)
165+
let cmp = ((a0, a1), (b0, b1)) =>
166+
switch Pervasives.compare(a0, b0) {
167+
| 0 => Pervasives.compare(a1, b1)
168+
| c => c
176169
}
177-
)
170+
})
178171
179172
let mySet2 = Belt.Set.make(~id=module(Comparable2))
180173
```
@@ -184,8 +177,8 @@ Here, the compiler would infer `mySet1` and `mySet2` having different type, so e
184177
## Examples
185178
186179
```rescript
187-
let mySet1: t<(int, int), Comparable1.identity>
188-
let mySet2: t<(int, int), Comparable2.identity>
180+
let mySet1: t<(int, int), Comparable1.identity> = %todo
181+
let mySet2: t<(int, int), Comparable2.identity> = %todo
189182
```
190183
191184
`Comparable1.identity` and `Comparable2.identity` are not the same using our encoding scheme.

runtime/Js.res

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,6 @@ For more information about these argument orders and the trade-offs between them
5252
5353
_Eventually, all modules in the Js namespace are going to be migrated to data-first though._
5454
55-
In the meantime, there are several options for dealing with the data-last APIs:
56-
57-
## Examples
58-
59-
```rescript
60-
/* Js.String (data-last API used with pipe last operator) */
61-
Js.log(\"2019-11-10\" |> Js.String.split(\"-\"))
62-
Js.log(\"ReScript\" |> Js.String.startsWith(\"Re\"))
63-
64-
/* Js.String (data-last API used with pipe first operator) */
65-
Js.log(\"2019-11-10\"->Js.String.split(\"-\", _))
66-
Js.log(\"ReScript\"->Js.String.startsWith(\"Re\", _))
67-
68-
/* Js.String (data-last API used without any piping) */
69-
Js.log(Js.String.split(\"-\", \"2019-11-10\"))
70-
Js.log(Js.String.startsWith(\"Re\", \"ReScript\"))
71-
```
7255
## Js.Xxx2 Modules
7356
7457
Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latters are old modules.

runtime/Js_array.res

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,6 @@
2626
Provides bindings to JavaScript’s `Array` functions. These bindings are
2727
optimized for pipe-last (`|>`), where the array to be processed is the last
2828
parameter in the function.
29-
30-
Here is an example to find the sum of squares of all even numbers in an array.
31-
Without pipe last, we must call the functions in reverse order:
32-
33-
## Examples
34-
35-
```rescript
36-
let isEven = x => mod(x, 2) == 0
37-
let square = x => x * x
38-
let result = {
39-
open Js.Array
40-
reduce(\"+", 0, map(square, filter(isEven, [5, 2, 3, 4, 1])))
41-
}
42-
```
43-
44-
With pipe last, we call the functions in the “natural” order:
45-
46-
```rescript
47-
let isEven = x => mod(x, 2) == 0
48-
let square = x => x * x
49-
let result = {
50-
open Js.Array
51-
[5, 2, 3, 4, 1] |> filter(isEven) |> map(square) |> reduce("+", 0)
52-
}
53-
```
5429
*/
5530

5631
@@warning("-103")
@@ -1090,7 +1065,7 @@ external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get"
10901065
/**
10911066
Sets the value at the given position in the array if the position is in bounds.
10921067
If the index is out of bounds, well, “here there be dragons.“ *This function
1093-
modifies the original array.*
1068+
modifies the original array.*
10941069
10951070
## Examples
10961071

runtime/Js_bigint.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Js.BigInt.fromStringExn("0o11")
2626
try {
2727
Js.BigInt.fromStringExn("a")
2828
} catch {
29-
| _ => ...
29+
| _ => Console.error("Error parsing bigint")
3030
}
3131
```
3232
*/

runtime/Js_string.res

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ external get: (t, int) => t = ""
140140
/**
141141
`charAt(n, s)` gets the character at index `n` within string `s`. If `n` is
142142
negative or greater than the length of `s`, it returns the empty string. If the
143-
string contains characters outside the range \u0000-\uffff, it will return the
143+
string contains characters outside the range \\u0000-\\uffff, it will return the
144144
first 16-bit value at that position in the string.
145145
146146
See [`String.charAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
@@ -336,7 +336,7 @@ let indexOf = (arg1, obj) => indexOf(obj, arg1)
336336
/**
337337
`indexOfFrom(searchValue, start, str)` returns the position at which
338338
`searchValue` was found within `str` starting at character position `start`, or
339-
-1 if `searchValue` is not found in that portion of `str`. The return value is
339+
\-1 if `searchValue` is not found in that portion of `str`. The return value is
340340
relative to the beginning of the string, no matter where the search started
341341
from.
342342
@@ -424,7 +424,7 @@ let localeCompare = (arg1, obj) => localeCompare(obj, arg1)
424424
/**
425425
`match(regexp, str)` matches a `string` against the given `regexp`. If there is
426426
no match, it returns `None`. For regular expressions without the g modifier, if
427-
there is a match, the return value is `Some(array)` where the array contains:
427+
there is a match, the return value is `Some(array)` where the array contains:
428428
- The entire matched string
429429
- Any capture groups if the regexp had parentheses
430430
@@ -738,7 +738,7 @@ on MDN.
738738
## Examples
739739
740740
```rescript
741-
Js.String.splitByRe(%re("/\s*[,;]\s*TODO/"), "art; bed , cog ;dad") == [
741+
Js.String.splitByRe(/\s*[,;]\s*TODO/, "art; bed , cog ;dad") == [
742742
Some("art"),
743743
Some("bed"),
744744
Some("cog"),
@@ -762,15 +762,15 @@ on MDN.
762762
## Examples
763763
764764
```rescript
765-
Js.String.splitByReAtMost(%re("/\s*[,;]\s*TODO/"), ~limit=3, "one: two: three: four") == [
765+
Js.String.splitByReAtMost(/\s*[,;]\s*TODO/, ~limit=3, "one: two: three: four") == [
766766
Some("one"),
767767
Some("two"),
768768
Some("three"),
769769
]
770770
771-
Js.String.splitByReAtMost(%re("/\s*[,;]\s*TODO/"), ~limit=0, "one: two: three: four") == []
771+
Js.String.splitByReAtMost(/\s*[,;]\s*TODO/, ~limit=0, "one: two: three: four") == []
772772
773-
Js.String.splitByReAtMost(%re("/\s*[,;]\s*TODO/"), ~limit=8, "one: two: three: four") == [
773+
Js.String.splitByReAtMost(/\s*[,;]\s*TODO/, ~limit=8, "one: two: three: four") == [
774774
Some("one"),
775775
Some("two"),
776776
Some("three"),
@@ -1000,7 +1000,7 @@ on MDN.
10001000
## Examples
10011001
10021002
```rescript
1003-
Js.String.anchor("page1", "Page One") == "<a name="page1">Page One</a>"
1003+
Js.String.anchor("page1", "Page One") == "<a name=\"page1\">Page One</a>"
10041004
```
10051005
*/
10061006
@send
@@ -1018,7 +1018,7 @@ on MDN.
10181018
## Examples
10191019
10201020
```rescript
1021-
Js.String.link("page2.html", "Go to page two") == "<a href="page2.html">Go to page two</a>"
1021+
Js.String.link("page2.html", "Go to page two") == "<a href=\"page2.html\">Go to page two</a>"
10221022
```
10231023
*/
10241024
@send

runtime/Js_string2.res

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ external get: (t, int) => t = ""
145145
/**
146146
`charAt(s, n)` gets the character at index `n` within string `s`. If `n` is
147147
negative or greater than the length of `s`, it returns the empty string. If the
148-
string contains characters outside the range \u0000-\uffff, it will return the
148+
string contains characters outside the range \\u0000-\\uffff, it will return the
149149
first 16-bit value at that position in the string.
150150
151151
See [`String.charAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
@@ -331,7 +331,7 @@ external indexOf: (t, t) => int = "indexOf"
331331
/**
332332
`indexOfFrom(str, searchValue, start)` returns the position at which
333333
`searchValue` was found within `str` starting at character position `start`, or
334-
-1 if `searchValue` is not found in that portion of `str`. The return value is
334+
\-1 if `searchValue` is not found in that portion of `str`. The return value is
335335
relative to the beginning of the string, no matter where the search started
336336
from.
337337
@@ -415,11 +415,11 @@ external localeCompare: (t, t) => float = "localeCompare"
415415
/**
416416
`match(str, regexp)` matches a `string` against the given `regexp`. If there is
417417
no match, it returns `None`. For regular expressions without the g modifier, if
418-
there is a match, the return value is `Some(array)` where the array contains:
418+
there is a match, the return value is `Some(array)` where the array contains:
419419
- The entire matched string
420420
- Any capture groups if the regexp had parentheses
421-
For regular expressions with the g modifier, a matched expression returns
422-
`Some(array)` with all the matched substrings and no capture groups.
421+
For regular expressions with the g modifier, a matched expression returns
422+
`Some(array)` with all the matched substrings and no capture groups.
423423
424424
See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
425425
on MDN.
@@ -956,7 +956,7 @@ on MDN.
956956
## Examples
957957
958958
```rescript
959-
Js.String2.anchor("Page One", "page1") == "<a name="page1">Page One</a>"
959+
Js.String2.anchor("Page One", "page1") == "<a name=\"page1\">Page One</a>"
960960
```
961961
*/
962962
@send
@@ -972,7 +972,7 @@ on MDN.
972972
## Examples
973973
974974
```rescript
975-
Js.String2.link("Go to page two", "page2.html") == "<a href="page2.html">Go to page two</a>"
975+
Js.String2.link("Go to page two", "page2.html") == "<a href=\"page2.html\">Go to page two</a>"
976976
```
977977
*/
978978
@send

0 commit comments

Comments
 (0)