Skip to content

Commit 3f6f686

Browse files
authored
[Belt] Change ofArray to fromArray, and ofFoo to fromFoo in general (#2590)
* [Belt] Change ofArray to fromArray, and ofFoo to fromFoo in general Discussed offline. Easier API to guess. Only changed the externally visible APIs. Didn't check in the JS files; too much noise for now. * Change internal ofFoo to fromFoo too * One last ofArray* * Update tests * Check in js artifacts to make tests pass
1 parent c656c7b commit 3f6f686

File tree

100 files changed

+701
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+701
-455
lines changed

jscomp/others/belt_HashMap.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ let make (type key) (type identity) ~hintSize ~(id : (key,identity) id) =
201201
C.make ~hash:M.hash ~eq:M.eq ~hintSize
202202

203203

204-
let ofArray (type a) (type identity) arr ~id:(id:(a,identity) id) =
204+
let fromArray (type a) (type identity) arr ~id:(id:(a,identity) id) =
205205
let module M = (val id) in
206206
let hash, eq = M.hash, M.eq in
207207
let len = A.length arr in
@@ -212,6 +212,8 @@ let ofArray (type a) (type identity) arr ~id:(id:(a,identity) id) =
212212
set0 ~eq ~hash v key value
213213
done ;
214214
v
215+
216+
let ofArray = fromArray
215217

216218
let mergeMany h arr =
217219
let hash, eq = Belt_Id.getHashInternal ( C.hash h) , Belt_Id.getEqInternal (C.eq h) in

jscomp/others/belt_HashMap.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ val size: _ t -> int
149149
val toArray: ('key, 'value, 'id ) t -> ('key * 'value) array
150150
val keysToArray: ('key, _, _) t -> 'key array
151151
val valuesToArray: (_,'value,_) t -> 'value array
152-
val ofArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
152+
val fromArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
153153
val mergeMany: ('key, 'value, 'id ) t -> ('key * 'value) array -> unit
154154
val getBucketHistogram: _ t -> int array
155155
val logStats: _ t -> unit
156156

157+
val ofArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
158+
[@@ocaml.deprecated "Use fromArray instead"]
157159

jscomp/others/belt_HashMapInt.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ let valuesToArray = N.valuesToArray
187187
let getBucketHistogram = N.getBucketHistogram
188188
let isEmpty = C.isEmpty
189189

190-
let ofArray arr =
190+
let fromArray arr =
191191
let len = A.length arr in
192192
let v = make len in
193193
for i = 0 to len - 1 do
@@ -196,6 +196,8 @@ let ofArray arr =
196196
done ;
197197
v
198198

199+
let ofArray = fromArray
200+
199201
(* TOOD: optimize heuristics for resizing *)
200202
let mergeMany h arr =
201203
let len = A.length arr in

jscomp/others/belt_HashMapInt.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ val size: _ t -> int
4242
val toArray: 'a t -> (key * 'a) array
4343
val keysToArray: 'a t -> key array
4444
val valuesToArray: 'a t -> 'a array
45-
val ofArray: (key * 'a) array -> 'a t
45+
val fromArray: (key * 'a) array -> 'a t
4646
val mergeMany: 'a t -> (key * 'a) array -> unit
4747
val getBucketHistogram: _ t -> int array
4848
val logStats: _ t -> unit
49+
50+
val ofArray: (key * 'a) array -> 'a t
51+
[@@ocaml.deprecated "Use fromArray instead"]

jscomp/others/belt_HashMapString.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ let valuesToArray = N.valuesToArray
187187
let getBucketHistogram = N.getBucketHistogram
188188
let isEmpty = C.isEmpty
189189

190-
let ofArray arr =
190+
let fromArray arr =
191191
let len = A.length arr in
192192
let v = make len in
193193
for i = 0 to len - 1 do
@@ -196,6 +196,8 @@ let ofArray arr =
196196
done ;
197197
v
198198

199+
let ofArray = fromArray
200+
199201
(* TOOD: optimize heuristics for resizing *)
200202
let mergeMany h arr =
201203
let len = A.length arr in

jscomp/others/belt_HashMapString.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ val size: _ t -> int
4242
val toArray: 'a t -> (key * 'a) array
4343
val keysToArray: 'a t -> key array
4444
val valuesToArray: 'a t -> 'a array
45-
val ofArray: (key * 'a) array -> 'a t
45+
val fromArray: (key * 'a) array -> 'a t
4646
val mergeMany: 'a t -> (key * 'a) array -> unit
4747
val getBucketHistogram: _ t -> int array
4848
val logStats: _ t -> unit
49+
50+
val ofArray: (key * 'a) array -> 'a t
51+
[@@ocaml.deprecated "Use fromArray instead"]

jscomp/others/belt_HashSet.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ let copy = N.copy
176176
let getBucketHistogram = N.getBucketHistogram
177177
let isEmpty = C.isEmpty
178178

179-
let ofArray (type a) (type identity) arr ~(id:(a,identity) id) =
179+
let fromArray (type a) (type identity) arr ~(id:(a,identity) id) =
180180
let module M = (val id) in
181181
let eq, hash = M.eq , M.hash in
182182
let len = A.length arr in
@@ -186,6 +186,7 @@ let ofArray (type a) (type identity) arr ~(id:(a,identity) id) =
186186
done ;
187187
v
188188

189+
let ofArray = fromArray
189190

190191
let mergeMany h arr =
191192
let eq, hash = C.eq h, C.hash h in

jscomp/others/belt_HashSet.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ val logStats: _ t -> unit
117117
val toArray: ('a,'id) t -> 'a array
118118

119119
val ofArray: 'a array -> id:('a,'id) id -> ('a,'id) t
120+
[@@ocaml.deprecated "Use fromArray instead"]
121+
122+
val fromArray: 'a array -> id:('a,'id) id -> ('a,'id) t
120123

121124
val mergeMany: ('a,'id) t -> 'a array -> unit
122125

jscomp/others/belt_HashSetInt.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,16 @@ let copy = N.copy
138138
let getBucketHistogram = N.getBucketHistogram
139139
let isEmpty = C.isEmpty
140140

141-
let ofArray arr =
141+
let fromArray arr =
142142
let len = A.length arr in
143143
let v = C.make ~hintSize:len ~hash:() ~eq:() in
144144
for i = 0 to len - 1 do
145145
add v (A.getUnsafe arr i)
146146
done ;
147147
v
148148

149+
let ofArray = fromArray
150+
149151
(* TOOD: optimize heuristics for resizing *)
150152
let mergeMany h arr =
151153
let len = A.length arr in

jscomp/others/belt_HashSetInt.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ val logStats: t -> unit
6767
val toArray: t -> key array
6868

6969
val ofArray: key array -> t
70+
[@@ocaml.deprecated "Use fromArray instead"]
71+
72+
val fromArray: key array -> t
7073

7174
val mergeMany: t -> key array -> unit
7275

0 commit comments

Comments
 (0)