Skip to content

Commit a1630ea

Browse files
committed
Array.joinWith -> Array.join
1 parent 6d2d3d8 commit a1630ea

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

scripts/DocTests.res

+4-4
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ let testCode = async (~id, ~code) => {
184184
| true =>
185185
promise
186186
->Array.map(e => e->Buffer.toString)
187-
->Array.joinWith("")
187+
->Array.join(~separator="")
188188
->Error
189189
| false => Ok()
190190
}
@@ -259,7 +259,7 @@ let getCodeBlocks = example => {
259259
code
260260
->List.reverse
261261
->List.toArray
262-
->Array.joinWith("\n"),
262+
->Array.join(~separator="\n"),
263263
...acc,
264264
},
265265
)
@@ -325,9 +325,9 @@ let main = async () => {
325325
e
326326
->String.split("\n")
327327
->Array.filterWithIndex((_, i) => i !== 2)
328-
->Array.joinWith("\n")
328+
->Array.join(~separator="\n")
329329
})
330-
->Array.joinWith("\n")
330+
->Array.join(~separator="\n")
331331

332332
let message = `${"error"->red}: failed to compile examples from ${kind} ${test.id->cyan}\n${errorMessage}`
333333

src/Core__Array.res

+8-2
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,15 @@ let indexOfOpt = (arr, item) =>
124124
}
125125
@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf"
126126

127-
@send external joinWith: (array<string>, string) => string = "join"
127+
@send external join: (array<string>, ~separator: string=?) => string = "join"
128128

129-
@send external joinWithUnsafe: (array<'a>, string) => string = "join"
129+
@deprecated("Use `join` instead") @send
130+
external joinWith: (array<string>, string) => string = "join"
131+
132+
@send external joinUnsafe: (array<'a>, ~separator: string=?) => string = "join"
133+
134+
@deprecated("Use `joinUnsafe` instead") @send
135+
external joinWithUnsafe: (array<'a>, string) => string = "join"
130136

131137
@send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf"
132138
let lastIndexOfOpt = (arr, item) =>

src/Core__Array.resi

+36
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,23 @@ Console.log([{"language": "ReScript"}]->Array.indexOfOpt({"language": "ReScript"
397397
let indexOfOpt: (array<'a>, 'a) => option<int>
398398
@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf"
399399

400+
/**
401+
`join(array, ~separator=?)` produces a string where all items of `array` are printed, separated by `separator`. If no separator is specified, `,` is used as the default. Array items must be strings, to join number or other arrays, use `joinWithUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.
402+
403+
See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
404+
405+
## Examples
406+
```rescript
407+
let array = ["One", "Two", "Three"]
408+
409+
Console.log(array->Array.join) // One,Two,Three
410+
411+
Console.log(array->Array.join(~separator=" -- ")) // One -- Two -- Three
412+
```
413+
*/
414+
@send
415+
external join: (array<string>, ~separator: string=?) => string = "join"
416+
400417
/**
401418
`joinWith(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinWithUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.
402419

@@ -407,9 +424,27 @@ let array = ["One", "Two", "Three"]
407424
Console.log(array->Array.joinWith(" -- ")) // One -- Two -- Three
408425
```
409426
*/
427+
@deprecated("Use `join` instead")
410428
@send
411429
external joinWith: (array<string>, string) => string = "join"
412430

431+
/**
432+
`joinUnsafe(array, ~separator=?)` produces a string where all items of `array` are printed, separated by `separator`. If no separator is specified, `,` is used as the default. Under the hood this will run JavaScript's `toString` on all the array items.
433+
434+
See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
435+
436+
## Examples
437+
```rescript
438+
let array = [1, 2, 3]
439+
440+
Console.log(array->Array.joinUnsafe) // 1,2,3
441+
442+
Console.log(array->Array.joinUnsafe(~separator=" -- ")) // 1 -- 2 -- 3
443+
```
444+
*/
445+
@send
446+
external joinUnsafe: (array<'a>, ~separator: string=?) => string = "join"
447+
413448
/**
414449
`joinWithUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.
415450

@@ -420,6 +455,7 @@ let array = [1, 2, 3]
420455
Console.log(array->Array.joinWithUnsafe(" -- ")) // 1 -- 2 -- 3
421456
```
422457
*/
458+
@deprecated("Use `joinUnsafe` instead")
423459
@send
424460
external joinWithUnsafe: (array<'a>, string) => string = "join"
425461
@send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf"

0 commit comments

Comments
 (0)