diff --git a/CHANGELOG.md b/CHANGELOG.md index 23dc8533..626ee70c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### API changes - Add `Math.Int.floor` and `Math.Int.random`, https://github.com/rescript-association/rescript-core/pull/156 +- Change `Array.joinWith`s signature to accept only string arrays and add `Array.joinWithUnsafe` with the polymorphic signature of the former https://github.com/rescript-association/rescript-core/pull/157 ### Documentation diff --git a/src/Core__Array.res b/src/Core__Array.res index 0f8be4e5..954cb99b 100644 --- a/src/Core__Array.res +++ b/src/Core__Array.res @@ -123,7 +123,9 @@ let indexOfOpt = (arr, item) => } @send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf" -@send external joinWith: (array<'a>, string) => string = "join" +@send external joinWith: (array, string) => string = "join" + +@send external joinWithUnsafe: (array<'a>, string) => string = "join" @send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf" let lastIndexOfOpt = (arr, item) => diff --git a/src/Core__Array.resi b/src/Core__Array.resi index c4fbd938..998b9178 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -384,17 +384,30 @@ let indexOfOpt: (array<'a>, 'a) => option @send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf" /** -`joinWith(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. +`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. + +## Examples +```rescript +let array = ["One", "Two", "Three"] + +Console.log(array->Array.joinWith(" -- ")) // One -- Two -- Three +``` +*/ +@send +external joinWith: (array, 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. ## Examples ```rescript let array = [1, 2, 3] -Console.log(array->Array.joinWith(" -- ")) // 1 -- 2 -- 3 +Console.log(array->Array.joinWithUnsafe(" -- ")) // 1 -- 2 -- 3 ``` */ @send -external joinWith: (array<'a>, string) => string = "join" +external joinWithUnsafe: (array<'a>, string) => string = "join" @send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf" let lastIndexOfOpt: (array<'a>, 'a) => option @send external lastIndexOfFrom: (array<'a>, 'a, int) => int = "lastIndexOf"