Skip to content

Commit

Permalink
Array.joinWith -> Array.join
Browse files Browse the repository at this point in the history
  • Loading branch information
cknitt committed Apr 1, 2024
1 parent 6d2d3d8 commit dedd5f6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next version

- Add `Array.join` and deprecate `Array.joinWith`. https://github.com/rescript-association/rescript-core/pull/205
- BREAKING: Intl types: simplify bindings for constructors / functions with optional arguments. https://github.com/rescript-association/rescript-core/pull/198
- Fix: Expose Intl.Common. https://github.com/rescript-association/rescript-core/pull/197
- Add `Array.flatMapWithIndex` https://github.com/rescript-association/rescript-core/pull/199
Expand Down
2 changes: 1 addition & 1 deletion scripts/DocTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function testCode(id, code) {
"-I",
rescriptCoreCompiled,
"-w",
"-109",
"-3-109",
"-uncurried",
"-open",
"RescriptCore"
Expand Down
10 changes: 5 additions & 5 deletions scripts/DocTests.res
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ let testCode = async (~id, ~code) => {
"-I",
rescriptCoreCompiled,
"-w",
"-109",
"-3-109",
"-uncurried",
"-open",
"RescriptCore",
Expand All @@ -184,7 +184,7 @@ let testCode = async (~id, ~code) => {
| true =>
promise
->Array.map(e => e->Buffer.toString)
->Array.joinWith("")
->Array.join("")
->Error
| false => Ok()
}
Expand Down Expand Up @@ -259,7 +259,7 @@ let getCodeBlocks = example => {
code
->List.reverse
->List.toArray
->Array.joinWith("\n"),
->Array.join("\n"),
...acc,
},
)
Expand Down Expand Up @@ -325,9 +325,9 @@ let main = async () => {
e
->String.split("\n")
->Array.filterWithIndex((_, i) => i !== 2)
->Array.joinWith("\n")
->Array.join("\n")
})
->Array.joinWith("\n")
->Array.join("\n")

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

Expand Down
10 changes: 8 additions & 2 deletions src/Core__Array.res
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,15 @@ let indexOfOpt = (arr, item) =>
}
@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf"

@send external joinWith: (array<string>, string) => string = "join"
@send external join: (array<string>, string) => string = "join"

@send external joinWithUnsafe: (array<'a>, string) => string = "join"
@deprecated("Use `join` instead") @send
external joinWith: (array<string>, string) => string = "join"

@send external joinUnsafe: (array<'a>, string) => string = "join"

@deprecated("Use `joinUnsafe` instead") @send
external joinWithUnsafe: (array<'a>, string) => string = "join"

@send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf"
let lastIndexOfOpt = (arr, item) =>
Expand Down
32 changes: 32 additions & 0 deletions src/Core__Array.resi
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,21 @@ Console.log([{"language": "ReScript"}]->Array.indexOfOpt({"language": "ReScript"
let indexOfOpt: (array<'a>, 'a) => option<int>
@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf"

/**
`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.
See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
## Examples
```rescript
let array = ["One", "Two", "Three"]
Console.log(array->Array.join(" -- ")) // One -- Two -- Three
```
*/
@send
external join: (array<string>, string) => string = "join"

/**
`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.
Expand All @@ -407,9 +422,25 @@ let array = ["One", "Two", "Three"]
Console.log(array->Array.joinWith(" -- ")) // One -- Two -- Three
```
*/
@deprecated("Use `join` instead")
@send
external joinWith: (array<string>, string) => string = "join"

/**
`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.
See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
## Examples
```rescript
let array = [1, 2, 3]
Console.log(array->Array.joinUnsafe(" -- ")) // 1 -- 2 -- 3
```
*/
@send
external joinUnsafe: (array<'a>, string) => string = "join"

/**
`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.
Expand All @@ -420,6 +451,7 @@ let array = [1, 2, 3]
Console.log(array->Array.joinWithUnsafe(" -- ")) // 1 -- 2 -- 3
```
*/
@deprecated("Use `joinUnsafe` instead")
@send
external joinWithUnsafe: (array<'a>, string) => string = "join"
@send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf"
Expand Down

0 comments on commit dedd5f6

Please sign in to comment.