Skip to content

Commit dedd5f6

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

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next version
44

5+
- Add `Array.join` and deprecate `Array.joinWith`. https://github.com/rescript-association/rescript-core/pull/205
56
- BREAKING: Intl types: simplify bindings for constructors / functions with optional arguments. https://github.com/rescript-association/rescript-core/pull/198
67
- Fix: Expose Intl.Common. https://github.com/rescript-association/rescript-core/pull/197
78
- Add `Array.flatMapWithIndex` https://github.com/rescript-association/rescript-core/pull/199

scripts/DocTests.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async function testCode(id, code) {
143143
"-I",
144144
rescriptCoreCompiled,
145145
"-w",
146-
"-109",
146+
"-3-109",
147147
"-uncurried",
148148
"-open",
149149
"RescriptCore"

scripts/DocTests.res

+5-5
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ let testCode = async (~id, ~code) => {
163163
"-I",
164164
rescriptCoreCompiled,
165165
"-w",
166-
"-109",
166+
"-3-109",
167167
"-uncurried",
168168
"-open",
169169
"RescriptCore",
@@ -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("")
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("\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("\n")
329329
})
330-
->Array.joinWith("\n")
330+
->Array.join("\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>, 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>, 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

+32
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,21 @@ 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`. Array items must be strings, to join number or other arrays, use `joinUnsafe`. 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+
*/
412+
@send
413+
external join: (array<string>, string) => string = "join"
414+
400415
/**
401416
`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.
402417

@@ -407,9 +422,25 @@ let array = ["One", "Two", "Three"]
407422
Console.log(array->Array.joinWith(" -- ")) // One -- Two -- Three
408423
```
409424
*/
425+
@deprecated("Use `join` instead")
410426
@send
411427
external joinWith: (array<string>, string) => string = "join"
412428

429+
/**
430+
`joinUnsafe(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.
431+
432+
See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
433+
434+
## Examples
435+
```rescript
436+
let array = [1, 2, 3]
437+
438+
Console.log(array->Array.joinUnsafe(" -- ")) // 1 -- 2 -- 3
439+
```
440+
*/
441+
@send
442+
external joinUnsafe: (array<'a>, string) => string = "join"
443+
413444
/**
414445
`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.
415446

@@ -420,6 +451,7 @@ let array = [1, 2, 3]
420451
Console.log(array->Array.joinWithUnsafe(" -- ")) // 1 -- 2 -- 3
421452
```
422453
*/
454+
@deprecated("Use `joinUnsafe` instead")
423455
@send
424456
external joinWithUnsafe: (array<'a>, string) => string = "join"
425457
@send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf"

0 commit comments

Comments
 (0)