Skip to content

Commit

Permalink
Fix Array.joinWith
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Aug 9, 2023
1 parent 2bbf848 commit c601d66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions packages/belt/src/belt_Array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,18 @@ let reduceWithIndexU a x f =

let reduceWithIndex a x f = reduceWithIndexU a x (fun a b c -> f a b c)

let joinWithU a sep toString =
let joinWithU a sep =
match length a with
| 0 -> ""
| l ->
let lastIndex = l - 1 in
let rec aux i res =
let v = getUnsafe a i in
if i = lastIndex then res ^ toString v
else aux (i + 1) (res ^ toString v ^ sep)
if i = lastIndex then res ^ v else aux (i + 1) (res ^ v ^ sep)
in
aux 0 ""

let joinWith a sep toString = joinWithU a sep (fun x -> toString x)
let joinWith a sep = joinWithU a sep
let initU n f = Stdlib.Array.init n f
let init n f = initU n (fun i -> f i)

Expand Down
4 changes: 2 additions & 2 deletions packages/belt/src/belt_Array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ val reduceWithIndex : 'a t -> 'b -> ('b -> 'a -> int -> 'b) -> 'b
]}
*)

val joinWithU : 'a t -> string -> (('a -> string)[@bs]) -> string
val joinWithU : string t -> string -> string

val joinWith : 'a t -> string -> ('a -> string) -> string
val joinWith : string t -> string -> string
(** [joinWith xs sep toString]
Concatenates all the elements of [xs] converted to string with [toString], each separated by [sep], the string
Expand Down

0 comments on commit c601d66

Please sign in to comment.