Skip to content

Commit 2c947d3

Browse files
authored
[Belt] Use 'v instead of 'a for interface signature (#2578)
Makes things a bit more consistent. @bobzhang so the set API uses `('value, 'id) t` but map here mostly uses `('k, 'v, 'id) t` to stay more concise, since `('key, 'value, 'id) t` in every signature might be a bit verbose. Or is it? If it's not, I'd gladly do `('key, 'v, 'id) t` or `('key, 'value, 'id) t`.
1 parent fddddfe commit 2c947d3

File tree

4 files changed

+244
-242
lines changed

4 files changed

+244
-242
lines changed

jscomp/others/belt_Map.mli

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,18 @@ module String = Belt_MapString
8282
module Dict = Belt_MapDict
8383

8484

85-
type ('key,'value,'identity) t
85+
type ('key, 'value, 'identity) t
8686
(** [('key, 'identity) t]
8787
88-
['key] is the element type
88+
['key] is the field type
89+
90+
['value] is the element type
8991
9092
['identity] the identity of the collection
9193
*)
9294

9395

94-
type ('key, 'id ) id = ('key, 'id) Belt_Id.comparable
96+
type ('key, 'id) id = ('key, 'id) Belt_Id.comparable
9597
(** The identity needed for making an empty map*)
9698

9799

@@ -118,7 +120,7 @@ type ('key, 'id ) id = ('key, 'id) Belt_Id.comparable
118120
should only export [Belt_Id.t] or [Belt_Id.cmp] instead *)
119121

120122

121-
val make: id:('k, 'id) id -> ('k, 'a, 'id) t
123+
val make: id:('k, 'id) id -> ('k, 'v, 'id) t
122124
(** [make ~id]
123125
124126
@example {[
@@ -137,7 +139,7 @@ val isEmpty: _ t -> bool
137139
]}
138140
*)
139141

140-
val has: ('k, 'a, 'id) t -> 'k -> bool
142+
val has: ('k, 'v, 'id) t -> 'k -> bool
141143
(** [has s k]
142144
143145
@example {[
@@ -164,22 +166,22 @@ val cmp:
164166
*)
165167

166168
val eqU:
167-
('k, 'a, 'id) t ->
168-
('k, 'a, 'id) t ->
169-
('a -> 'a -> bool [@bs]) ->
169+
('k, 'v, 'id) t ->
170+
('k, 'v, 'id) t ->
171+
('v -> 'v -> bool [@bs]) ->
170172
bool
171173
val eq:
172-
('k, 'a, 'id) t ->
173-
('k, 'a, 'id) t ->
174-
('a -> 'a -> bool) ->
174+
('k, 'v, 'id) t ->
175+
('k, 'v, 'id) t ->
176+
('v -> 'v -> bool) ->
175177
bool
176178
(** [eq m1 m2 veq] tests whether the maps [m1] and [m2] are
177179
equal, that is, contain equal keys and associate them with
178180
equal data. [veq] is the equality predicate used to compare
179181
the data associated with the keys. *)
180182

181-
val forEachU: ('k, 'a, 'id) t -> ('k -> 'a -> unit [@bs]) -> unit
182-
val forEach: ('k, 'a, 'id) t -> ('k -> 'a -> unit) -> unit
183+
val forEachU: ('k, 'v, 'id) t -> ('k -> 'v -> unit [@bs]) -> unit
184+
val forEach: ('k, 'v, 'id) t -> ('k -> 'v -> unit) -> unit
183185
(** [forEach m f] applies [f] to all bindings in map [m].
184186
[f] receives the 'k as first argument, and the associated value
185187
as second argument. The bindings are passed to [f] in increasing
@@ -197,8 +199,8 @@ val forEach: ('k, 'a, 'id) t -> ('k -> 'a -> unit) -> unit
197199
]}
198200
*)
199201

200-
val reduceU: ('k, 'a, 'id) t -> 'b -> ('b -> 'k -> 'a -> 'b [@bs]) -> 'b
201-
val reduce: ('k, 'a, 'id) t -> 'acc -> ('acc -> 'k -> 'a -> 'acc) -> 'acc
202+
val reduceU: ('k, 'v, 'id) t -> 'acc -> ('acc -> 'k -> 'v -> 'acc [@bs]) -> 'acc
203+
val reduce: ('k, 'v, 'id) t -> 'acc -> ('acc -> 'k -> 'v -> 'acc) -> 'acc
202204
(** [reduce m a f] computes [(f kN dN ... (f k1 d1 a)...)],
203205
where [k1 ... kN] are the keys of all bindings in [m]
204206
(in increasing order), and [d1 ... dN] are the associated data.
@@ -212,17 +214,17 @@ val reduce: ('k, 'a, 'id) t -> 'acc -> ('acc -> 'k -> 'a -> 'acc) -> 'acc
212214
]}
213215
*)
214216

215-
val everyU: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
216-
val every: ('k, 'a, 'id) t -> ('k -> 'a -> bool) -> bool
217+
val everyU: ('k, 'v, 'id) t -> ('k -> 'v -> bool [@bs]) -> bool
218+
val every: ('k, 'v, 'id) t -> ('k -> 'v -> bool) -> bool
217219
(** [every m p] checks if all the bindings of the map
218220
satisfy the predicate [p]. Order unspecified *)
219221

220-
val someU: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
221-
val some: ('k, 'a, 'id) t -> ('k -> 'a -> bool) -> bool
222+
val someU: ('k, 'v, 'id) t -> ('k -> 'v -> bool [@bs]) -> bool
223+
val some: ('k, 'v, 'id) t -> ('k -> 'v -> bool) -> bool
222224
(** [some m p] checks if at least one binding of the map
223225
satisfy the predicate [p]. Order unspecified *)
224226

225-
val size: ('k, 'a, 'id) t -> int
227+
val size: ('k, 'v, 'id) t -> int
226228
(** [size s]
227229
228230
@example {[
@@ -231,7 +233,7 @@ val size: ('k, 'a, 'id) t -> int
231233
size (ofArray [2,"2"; 2,"1"; 3,"3"] ~id:(module IntCmp)) = 2 ;;
232234
]}
233235
*)
234-
val toArray: ('k, 'a, 'id) t -> ('k * 'a) array
236+
val toArray: ('k, 'v, 'id) t -> ('k * 'v) array
235237
(** [toArray s]
236238
237239
@example {[
@@ -241,21 +243,21 @@ val toArray: ('k, 'a, 'id) t -> ('k * 'a) array
241243
]}
242244
243245
*)
244-
val toList: ('k, 'a, 'id) t -> ('k * 'a) list
246+
val toList: ('k, 'v, 'id) t -> ('k * 'v) list
245247
(** In increasing order
246248
247249
{b See} {!toArray}
248250
*)
249251

250-
val ofArray: ('k * 'a) array -> id:('k,'id) id -> ('k,'a,'id) t
252+
val ofArray: ('k * 'v) array -> id:('k,'id) id -> ('k,'v,'id) t
251253
(** [ofArray kvs ~id]
252254
@example {[
253255
module IntCmp =
254256
(val Belt.Id.comparableU (fun[\@bs] (x:int) y -> Pervasives.compare x y));;
255257
toArray (ofArray [2,"2"; 1,"1"; 3,"3"] ~id:(module IntCmp)) = [1,"1";2,"2";3,"3"]
256258
]}
257259
*)
258-
val keysToArray: ('k, 'a, 'id) t -> 'k array
260+
val keysToArray: ('k, 'v, 'id) t -> 'k array
259261
(** [keysToArray s]
260262
261263
@example {[
@@ -265,7 +267,7 @@ val keysToArray: ('k, 'a, 'id) t -> 'k array
265267
[|1;2;3|];;
266268
]}
267269
*)
268-
val valuesToArray: ('k, 'a, 'id) t -> 'a array
270+
val valuesToArray: ('k, 'v, 'id) t -> 'v array
269271
(** [valuesToArray s]
270272
271273
@example {[
@@ -293,24 +295,24 @@ val maxKey: ('k, _, _) t -> 'k option
293295
val maxKeyUndefined: ('k, _, _) t -> 'k Js.undefined
294296
(** {b See} {!maxKey} *)
295297

296-
val minimum: ('k, 'a, _) t -> ('k * 'a) option
298+
val minimum: ('k, 'v, _) t -> ('k * 'v) option
297299
(** [minimum s]
298300
@return thte minimum key value pair, None if not exist
299301
*)
300302

301-
val minUndefined: ('k, 'a, _) t -> ('k * 'a) Js.undefined
303+
val minUndefined: ('k, 'v, _) t -> ('k * 'v) Js.undefined
302304
(** {b See} {!minimum} *)
303305

304-
val maximum: ('k, 'a, _) t -> ('k * 'a) option
306+
val maximum: ('k, 'v, _) t -> ('k * 'v) option
305307
(** [maximum s]
306308
@return thte maximum key value pair, None if not exist
307309
*)
308310

309-
val maxUndefined:('k, 'a, _) t -> ('k * 'a) Js.undefined
311+
val maxUndefined:('k, 'v, _) t -> ('k * 'v) Js.undefined
310312
(** {b See} {!maximum}
311313
*)
312314

313-
val get: ('k, 'a, 'id) t -> 'k -> 'a option
315+
val get: ('k, 'v, 'id) t -> 'k -> 'v option
314316
(** [get s k]
315317
316318
@example {[
@@ -323,21 +325,21 @@ val get: ('k, 'a, 'id) t -> 'k -> 'a option
323325
]}
324326
*)
325327

326-
val getUndefined: ('k, 'a, 'id) t -> 'k -> 'a Js.undefined
328+
val getUndefined: ('k, 'v, 'id) t -> 'k -> 'v Js.undefined
327329
(** {b See} {!get}
328330
329331
@return [undefined] when not found
330332
*)
331333
val getWithDefault:
332-
('k, 'a, 'id) t -> 'k -> 'a -> 'a
334+
('k, 'v, 'id) t -> 'k -> 'v -> 'v
333335
(** [getWithDefault s k default]
334336
335337
{b See} {!get}
336338
337339
@return [default] when [k] is not found
338340
339341
*)
340-
val getExn: ('k, 'a, 'id) t -> 'k -> 'a
342+
val getExn: ('k, 'v, 'id) t -> 'k -> 'v
341343
(** [getExn s k]
342344
343345
{b See} {!getExn}
@@ -347,7 +349,7 @@ val getExn: ('k, 'a, 'id) t -> 'k -> 'a
347349

348350
(****************************************************************************)
349351

350-
val remove: ('k, 'a, 'id) t -> 'k -> ('k, 'a, 'id) t
352+
val remove: ('k, 'v, 'id) t -> 'k -> ('k, 'v, 'id) t
351353
(** [remove m x] when [x] is not in [m], [m] is returned reference unchanged.
352354
353355
@example {[
@@ -364,7 +366,7 @@ val remove: ('k, 'a, 'id) t -> 'k -> ('k, 'a, 'id) t
364366
365367
*)
366368

367-
val removeMany: ('k, 'a, 'id) t -> 'k array -> ('k, 'a, 'id) t
369+
val removeMany: ('k, 'v, 'id) t -> 'k array -> ('k, 'v, 'id) t
368370
(** [removeMany s xs]
369371
370372
Removing each of [xs] to [s], note unlike {!remove},
@@ -373,7 +375,7 @@ val removeMany: ('k, 'a, 'id) t -> 'k array -> ('k, 'a, 'id) t
373375
*)
374376

375377
val set:
376-
('k, 'a, 'id) t -> 'k -> 'a -> ('k, 'a, 'id) t
378+
('k, 'v, 'id) t -> 'k -> 'v -> ('k, 'v, 'id) t
377379
(** [set m x y ] returns a map containing the same bindings as
378380
[m], with a new binding of [x] to [y]. If [x] was already bound
379381
in [m], its previous binding disappears.
@@ -390,8 +392,8 @@ val set:
390392
]}
391393
*)
392394

393-
val updateU: ('k, 'a, 'id) t -> 'k -> ('a option -> 'a option [@bs]) -> ('k, 'a, 'id) t
394-
val update: ('k, 'a, 'id) t -> 'k -> ('a option -> 'a option) -> ('k, 'a, 'id) t
395+
val updateU: ('k, 'v, 'id) t -> 'k -> ('v option -> 'v option [@bs]) -> ('k, 'v, 'id) t
396+
val update: ('k, 'v, 'id) t -> 'k -> ('v option -> 'v option) -> ('k, 'v, 'id) t
395397
(** [update m x f] returns a map containing the same bindings as
396398
[m], except for the binding of [x].
397399
Depending on the value of
@@ -402,7 +404,7 @@ val update: ('k, 'a, 'id) t -> 'k -> ('a option -> 'a option) -> ('k, 'a, 'id) t
402404
*)
403405

404406
val mergeMany:
405-
('k, 'a, 'id) t -> ('k * 'a) array -> ('k, 'a, 'id) t
407+
('k, 'v, 'id) t -> ('k * 'v) array -> ('k, 'v, 'id) t
406408
(** [mergeMany s xs]
407409
408410
Adding each of [xs] to [s], note unlike {!add},
@@ -411,49 +413,49 @@ val mergeMany:
411413
*)
412414

413415
val mergeU:
414-
('k, 'a, 'id ) t ->
415-
('k, 'b,'id) t ->
416-
('k -> 'a option -> 'b option -> 'c option [@bs]) ->
417-
('k, 'c,'id) t
416+
('k, 'v, 'id ) t ->
417+
('k, 'v2, 'id) t ->
418+
('k -> 'v option -> 'v2 option -> 'v3 option [@bs]) ->
419+
('k, 'v3, 'id) t
418420
val merge:
419-
('k, 'a, 'id ) t ->
420-
('k, 'b,'id) t ->
421-
('k -> 'a option -> 'b option -> 'c option) ->
422-
('k, 'c,'id) t
421+
('k, 'v, 'id ) t ->
422+
('k, 'v2, 'id) t ->
423+
('k -> 'v option -> 'v2 option -> 'v3 option) ->
424+
('k, 'v3, 'id) t
423425
(** [merge m1 m2 f] computes a map whose keys is a subset of keys of [m1]
424426
and of [m2]. The presence of each such binding, and the corresponding
425427
value, is determined with the function [f].
426428
*)
427429

428430

429431
val keepU:
430-
('k, 'a, 'id) t ->
431-
('k -> 'a -> bool [@bs]) ->
432-
('k, 'a, 'id) t
432+
('k, 'v, 'id) t ->
433+
('k -> 'v -> bool [@bs]) ->
434+
('k, 'v, 'id) t
433435
val keep:
434-
('k, 'a, 'id) t ->
435-
('k -> 'a -> bool) ->
436-
('k, 'a, 'id) t
436+
('k, 'v, 'id) t ->
437+
('k -> 'v -> bool) ->
438+
('k, 'v, 'id) t
437439
(** [keep m p] returns the map with all the bindings in [m]
438440
that satisfy predicate [p]. *)
439441

440442
val partitionU:
441-
('k, 'a, 'id) t ->
442-
('k -> 'a -> bool [@bs]) ->
443-
('k, 'a, 'id) t * ('k, 'a, 'id) t
443+
('k, 'v, 'id) t ->
444+
('k -> 'v -> bool [@bs]) ->
445+
('k, 'v, 'id) t * ('k, 'v, 'id) t
444446
val partition:
445-
('k, 'a, 'id) t ->
446-
('k -> 'a -> bool) ->
447-
('k, 'a, 'id) t * ('k, 'a, 'id) t
447+
('k, 'v, 'id) t ->
448+
('k -> 'v -> bool) ->
449+
('k, 'v, 'id) t * ('k, 'v, 'id) t
448450
(** [partition m p] returns a pair of maps [(m1, m2)], where
449451
[m1] contains all the bindings of [s] that satisfy the
450452
predicate [p], and [m2] is the map with all the bindings of
451453
[s] that do not satisfy [p].
452454
*)
453455

454456
val split:
455-
('k, 'a, 'id) t -> 'k ->
456-
(('k, 'a, 'id) t * ('k, 'a, 'id) t )* 'a option
457+
('k, 'v, 'id) t -> 'k ->
458+
(('k, 'v, 'id) t * ('k, 'v, 'id) t )* 'v option
457459
(** [split x m] returns a tuple [(l r), data], where
458460
[l] is the map with all the bindings of [m] whose 'k
459461
is strictly less than [x];
@@ -463,16 +465,16 @@ val split:
463465
or [Some v] if [m] binds [v] to [x].
464466
*)
465467

466-
val mapU: ('k, 'a, 'id) t -> ('a -> 'b [@bs]) -> ('k ,'b,'id ) t
467-
val map: ('k, 'a, 'id) t -> ('a -> 'b) -> ('k ,'b,'id ) t
468+
val mapU: ('k, 'v, 'id) t -> ('v -> 'v2 [@bs]) -> ('k, 'v2, 'id) t
469+
val map: ('k, 'v, 'id) t -> ('v -> 'v2) -> ('k, 'v2, 'id) t
468470
(** [map m f] returns a map with same domain as [m], where the
469471
associated value [a] of all bindings of [m] has been
470472
replaced by the result of the application of [f] to [a].
471473
The bindings are passed to [f] in increasing order
472474
with respect to the ordering over the type of the keys. *)
473475

474-
val mapWithKeyU: ('k, 'a, 'id) t -> ('k -> 'a -> 'b [@bs]) -> ('k, 'b, 'id) t
475-
val mapWithKey: ('k, 'a, 'id) t -> ('k -> 'a -> 'b) -> ('k, 'b, 'id) t
476+
val mapWithKeyU: ('k, 'v, 'id) t -> ('k -> 'v -> 'v2 [@bs]) -> ('k, 'v2, 'id) t
477+
val mapWithKey: ('k, 'v, 'id) t -> ('k -> 'v -> 'v2) -> ('k, 'v2, 'id) t
476478
(** [mapWithKey m f]
477479
478480
The same as {!map} except that [f] is supplied with one more argument: the key
@@ -482,7 +484,7 @@ val mapWithKey: ('k, 'a, 'id) t -> ('k -> 'a -> 'b) -> ('k, 'b, 'id) t
482484

483485

484486

485-
val getData: ('a, 'b, 'c) t -> ('a, 'b, 'c) Belt_MapDict.t
487+
val getData: ('k, 'v, 'id) t -> ('k, 'v, 'id) Belt_MapDict.t
486488
(** [getData s0]
487489
488490
{b Advanced usage only}
@@ -492,15 +494,15 @@ val getData: ('a, 'b, 'c) t -> ('a, 'b, 'c) Belt_MapDict.t
492494
without boxing
493495
*)
494496

495-
val getId: ('a, 'b, 'c) t -> ('a, 'c) id
497+
val getId: ('k, 'v, 'id) t -> ('k, 'id) id
496498
(** [getId s0]
497499
498500
{b Advanced usage only}
499501
500502
@return the identity of [s0]
501503
*)
502504

503-
val packIdData: id:('a, 'b) id -> data:('a, 'c, 'b) Belt_MapDict.t -> ('a, 'c, 'b) t
505+
val packIdData: id:('k, 'id) id -> data:('k, 'v, 'id) Belt_MapDict.t -> ('k, 'v, 'id) t
504506
(** [packIdData ~id ~data]
505507
506508
{b Advanced usage only}

0 commit comments

Comments
 (0)