2323 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
2525(* * {!Belt.List}
26-
26+
2727 Utilities for List data type.
28-
28+
2929 This module is compatible with original ocaml stdlib.
3030 In general, all functions comes with the original stdlib also
3131 applies to this collection, however, this module provides faster
32- and stack safer utilities
32+ and stack safer utilities
3333
3434*)
3535
@@ -52,11 +52,11 @@ val head: 'a t -> 'a option
5252 head [1;2;3] = Some 1 ;;
5353 ]}
5454*)
55- val headExn : 'a t -> 'a
55+ val headExn : 'a t -> 'a
5656(* * [headExn h]
5757
5858 {b See} {!head}
59-
59+
6060 {b raise} an exception if [h] is empty
6161
6262*)
@@ -68,12 +68,12 @@ val tail: 'a t -> 'a t option
6868 tail [1;2] = Some [2];;
6969 ]}
7070*)
71-
72- val tailExn : 'a t -> 'a t
71+
72+ val tailExn : 'a t -> 'a t
7373(* * [tailExn h]
7474
7575 {b See} {!tail}
76-
76+
7777 {b raise} an exception if [h] is empty
7878*)
7979
@@ -99,40 +99,40 @@ val getExn: 'a t -> int -> 'a
9999(* * [getExn xs n]
100100
101101 {b See} {!get}
102-
102+
103103 {b raise} an exception if [n] is larger than the length
104- *)
104+ *)
105105
106106val make : int -> 'a -> 'a t
107- (* * [make n v]
108-
109- - return a list of length [n] with each element filled with [v]
107+ (* * [make n v]
108+
109+ - return a list of length [n] with each element filled with [v]
110110 - return the empty list if [n] is negative
111111
112112 @example {[
113113 make 3 1 = [1;1;1]
114114 ]}
115115*)
116-
117- val makeByU : int -> (int -> 'a [@ bs]) -> 'a t
116+
117+ val makeByU : int -> (int -> 'a [@ bs]) -> 'a t
118118val makeBy : int -> (int -> 'a ) -> 'a t
119- (* * [makeBy n f]
120-
119+ (* * [makeBy n f]
120+
121121 - return a list of length [n] with element [i] initialized with [f i]
122122 - return the empty list if [n] is negative
123123
124124 @example {[
125125 makeBy 5 (fun i -> i) = [0;1;2;3;4]
126126 ]}
127- *)
127+ *)
128128
129- val shuffle : 'a t -> 'a t
129+ val shuffle : 'a t -> 'a t
130130(* * [shuffle xs]
131131 @return a new list in random order
132132*)
133133
134134
135- val drop : 'a t -> int -> 'a t option
135+ val drop : 'a t -> int -> 'a t option
136136(* * [drop xs n]
137137
138138 return the list obtained by dropping the first [n] elements,
@@ -145,7 +145,7 @@ val drop: 'a t -> int -> 'a t option
145145 ]}
146146*)
147147
148- val take : 'a t -> int -> 'a t option
148+ val take : 'a t -> int -> 'a t option
149149(* * [take xs n]
150150
151151 return a list with the first [n] elements from [xs],
@@ -158,17 +158,17 @@ val take: 'a t -> int -> 'a t option
158158 ]}
159159*)
160160
161- val splitAt : 'a t -> int -> ('a list * 'a list ) option
161+ val splitAt : 'a t -> int -> ('a list * 'a list ) option
162162(* *
163163 [splitAt xs n]
164164 split the list [xs] at position [n]
165165 return None when the length of [xs] is less than [n]
166166
167167 @example{[
168168 splitAt [0;1;2;3;4] 2 = Some ([0;1], [2;3;4])
169- ]}
169+ ]}
170170*)
171-
171+
172172val concat : 'a t -> 'a t -> 'a t
173173(* *
174174 [concat xs ys]
@@ -197,7 +197,7 @@ val reverseConcat: 'a t -> 'a t -> 'a t
197197 reverseConcat [1;2] [3;4] = [2;1;3;4]
198198 ]}
199199*)
200-
200+
201201val flatten : 'a t t -> 'a t
202202(* *
203203 [flatten ls]
@@ -236,7 +236,7 @@ val zipBy: 'a t -> 'b t -> ('a -> 'b -> 'c) -> 'c t
236236(* * [zipBy xs ys f]
237237
238238 {b See} {!zip}
239-
239+
240240 Equivalent to [zip xs ys |> List.map (fun (x,y) -> f x y)]
241241*)
242242
@@ -248,10 +248,10 @@ val mapWithIndex: 'a t -> (int -> 'a -> 'b) -> 'b t
248248 ]}
249249*)
250250
251- val ofArray : 'a array -> 'a t
251+ val ofArray : 'a array -> 'a t
252252[@@ ocaml.deprecated "Use fromArray instead" ]
253253
254- val fromArray : 'a array -> 'a t
254+ val fromArray : 'a array -> 'a t
255255(* * @example {[
256256 fromArray [|1;2;3|] = [1;2;3]
257257 ]}
@@ -273,12 +273,12 @@ val reverse: 'a t -> 'a t
273273 reverse [1;2;3] = [3;2;1]
274274 ]}
275275*)
276-
276+
277277val mapReverseU : 'a t -> ('a -> 'b [@ bs]) -> 'b t
278278val mapReverse : 'a t -> ('a -> 'b ) -> 'b t
279279(* * [mapReverse a f]
280280
281- Equivalent to [reverse (map a f)]
281+ Equivalent to [reverse (map a f)]
282282*)
283283
284284val forEachU : 'a t -> ('a -> 'b [@ bs]) -> unit
@@ -290,7 +290,7 @@ val forEach: 'a t -> ('a -> 'b) -> unit
290290 !us = 1 + 2 + 3 + 4;;
291291 ]}
292292*)
293-
293+
294294val forEachWithIndexU : 'a t -> (int -> 'a -> 'b [@ bs]) -> unit
295295val forEachWithIndex : 'a t -> (int -> 'a -> 'b ) -> unit
296296(* * [forEachWithIndex xs f]
@@ -312,7 +312,7 @@ val reduce: 'a t -> 'b -> ('b -> 'a -> 'b) -> 'b
312312 reduce [1;2;3;4] [] add = [4;3;2;1];
313313 ]}
314314*)
315-
315+
316316val reduceReverseU : 'a t -> 'b -> ('b -> 'a -> 'b [@ bs]) -> 'b
317317val reduceReverse : 'a t -> 'b -> ('b -> 'a -> 'b ) -> 'b
318318(* * [reduceReverse xs f]
@@ -323,12 +323,12 @@ val reduceReverse: 'a t -> 'b -> ('b -> 'a -> 'b) -> 'b
323323 reduceReverse [1;2;3;4] [] add = [1;2;3;4];;
324324 ]}
325325*)
326-
326+
327327val mapReverse2U : 'a t -> 'b t -> ('a -> 'b -> 'c [@ bs]) -> 'c t
328328val mapReverse2 : 'a t -> 'b t -> ('a -> 'b -> 'c ) -> 'c t
329329(* * [mapReverse2 xs ys f]
330330
331- equivalent to [reverse (zipBy xs ys f)]
331+ equivalent to [reverse (zipBy xs ys f)]
332332
333333 @example {[
334334 mapReverse2 [1;2;3] [1;2] (+) = [4;2]
@@ -338,7 +338,7 @@ val mapReverse2: 'a t -> 'b t -> ('a -> 'b -> 'c) -> 'c t
338338val forEach2U : 'a t -> 'b t -> ('a -> 'b -> 'c [@ bs]) -> unit
339339val forEach2 : 'a t -> 'b t -> ('a -> 'b -> 'c ) -> unit
340340(* * [forEach2 xs ys f] stop with the shorter list
341- *)
341+ *)
342342
343343
344344val reduce2U :
@@ -347,7 +347,7 @@ val reduce2:
347347 'b t -> 'c t -> 'a -> ('a -> 'b -> 'c -> 'a ) -> 'a
348348(* * [reduce2 xs ys init f ]
349349
350- stops with the shorter list.
350+ stops with the shorter list.
351351*)
352352
353353val reduceReverse2U :
@@ -388,7 +388,7 @@ val every2: 'a t -> 'b t -> ('a -> 'b -> bool ) -> bool
388388(* * [every2 xs ys p] stop with the shorter list
389389 @example {[
390390 (every2 [] [1] (fun x y -> x > y)) = true;;
391- (every2 [2;3] [1] (fun x y -> x > y)) = true;;
391+ (every2 [2;3] [1] (fun x y -> x > y)) = true;;
392392 ]}
393393*)
394394
@@ -406,7 +406,7 @@ val cmpByLength: 'a t -> 'a t -> int
406406
407407 Compare two lists solely by length
408408*)
409-
409+
410410val cmpU : 'a t -> 'a t -> ('a -> 'a -> int [@ bs]) -> int
411411val cmp : 'a t -> 'a t -> ('a -> 'a -> int ) -> int
412412(* *
@@ -419,7 +419,7 @@ val cmp: 'a t -> 'a t -> ('a -> 'a -> int) -> int
419419
420420 {b Attention}: The total ordering of List is different from Array,
421421 for Array, we compare the length first and one by one later, while
422- for lists, we just compare one by one
422+ for lists, we just compare one by one
423423*)
424424
425425
@@ -433,7 +433,7 @@ val eq: 'a t -> 'a t -> ('a -> 'a -> bool) -> bool
433433 eq [1;2;3] [1;2] (=) = false ;;
434434 eq [1;2] [1;2] (=) = true
435435 ]}
436- *)
436+ *)
437437
438438
439439val hasU : 'a t -> 'b -> ('a -> 'b -> bool [@ bs]) -> bool
@@ -450,7 +450,7 @@ val getBy: 'a t -> ('a -> bool) -> 'a option
450450 getBy [1;4;3;2] (fun x -> x mod 2 = 0) = Some 4
451451 ]}
452452*)
453-
453+
454454val keepU : 'a t -> ('a -> bool [@ bs]) -> 'a t
455455val keep : 'a t -> ('a -> bool ) -> 'a t
456456(* * [keep xs p]
@@ -489,7 +489,7 @@ val unzip: ('a * 'b) t -> 'a t * 'b t
489489val getAssocU : ('a * 'c ) t -> 'b -> ('a -> 'b -> bool [@ bs]) -> 'c option
490490val getAssoc : ('a * 'c ) t -> 'b -> ('a -> 'b -> bool ) -> 'c option
491491(* * [getAssoc xs k eq]
492-
492+
493493 return the second element of a pair in [xs] where the first element equals [x],
494494 or [None] if not found
495495 @example {[
@@ -517,16 +517,16 @@ val removeAssoc: ('a * 'c) t -> 'b -> ('a -> 'b -> bool) -> ('a * 'c) t
517517*)
518518
519519val setAssocU : ('a * 'c ) t -> 'a -> 'c -> ('a -> 'a -> bool [@ bs]) -> ('a * 'c ) t
520- val setAssoc : ('a * 'c ) t -> 'a -> 'c -> ('a -> 'a -> bool ) -> ('a * 'c ) t
520+ val setAssoc : ('a * 'c ) t -> 'a -> 'c -> ('a -> 'a -> bool ) -> ('a * 'c ) t
521521(* * [setAssoc xs k v eq]
522522 if [k] exists in [xs], replace it with the new [v], otherwise, add
523523 it to the head
524524 @example {[
525525 setAssoc [1,"a"; 2, "b"; 3, "c"] 2 "x" (=) =
526- [1,"a"; 2, "x"; 3,"c"] ;;
526+ [1,"a"; 2, "x"; 3,"c"] ;;
527527
528- setAssoc [1,"a"; 3, "c"] 2 "2" (=) =
529- [2,"2"; 1,"a"; 3, "c"]
528+ setAssoc [1,"a"; 3, "c"] 2 "2" (=) =
529+ [2,"2"; 1,"a"; 3, "c"]
530530 ]}
531531*)
532532
@@ -536,6 +536,6 @@ val sort: 'a t -> ('a -> 'a -> int) -> 'a t
536536(* * [sort xs]
537537 Returns a sorted list.
538538 @example {[
539- sort (fun a b -> a - b) [5; 4; 9; 3; 7] = [3; 4; 5; 7; 9]
539+ sort [5; 4; 9; 3; 7] (fun a b -> a - b) = [3; 4; 5; 7; 9]
540540 ]}
541541*)
0 commit comments