File: Stdlib.List.html

package info (click to toggle)
ocaml-doc 4.11-2
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 20,580 kB
  • sloc: sh: 37; makefile: 11
file content (682 lines) | stat: -rw-r--r-- 37,842 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="Stdlib.Lexing.html">
<link rel="next" href="Stdlib.ListLabels.html">
<link rel="Up" href="Stdlib.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of extensions" rel=Appendix href="index_extensions.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Arg" rel="Chapter" href="Arg.html">
<link title="Array" rel="Chapter" href="Array.html">
<link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html">
<link title="Bigarray" rel="Chapter" href="Bigarray.html">
<link title="Bool" rel="Chapter" href="Bool.html">
<link title="Buffer" rel="Chapter" href="Buffer.html">
<link title="Bytes" rel="Chapter" href="Bytes.html">
<link title="BytesLabels" rel="Chapter" href="BytesLabels.html">
<link title="Callback" rel="Chapter" href="Callback.html">
<link title="CamlinternalFormat" rel="Chapter" href="CamlinternalFormat.html">
<link title="CamlinternalFormatBasics" rel="Chapter" href="CamlinternalFormatBasics.html">
<link title="CamlinternalLazy" rel="Chapter" href="CamlinternalLazy.html">
<link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html">
<link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html">
<link title="Char" rel="Chapter" href="Char.html">
<link title="Complex" rel="Chapter" href="Complex.html">
<link title="Condition" rel="Chapter" href="Condition.html">
<link title="Digest" rel="Chapter" href="Digest.html">
<link title="Dynlink" rel="Chapter" href="Dynlink.html">
<link title="Ephemeron" rel="Chapter" href="Ephemeron.html">
<link title="Event" rel="Chapter" href="Event.html">
<link title="Filename" rel="Chapter" href="Filename.html">
<link title="Float" rel="Chapter" href="Float.html">
<link title="Format" rel="Chapter" href="Format.html">
<link title="Fun" rel="Chapter" href="Fun.html">
<link title="Gc" rel="Chapter" href="Gc.html">
<link title="Genlex" rel="Chapter" href="Genlex.html">
<link title="Hashtbl" rel="Chapter" href="Hashtbl.html">
<link title="Int" rel="Chapter" href="Int.html">
<link title="Int32" rel="Chapter" href="Int32.html">
<link title="Int64" rel="Chapter" href="Int64.html">
<link title="Lazy" rel="Chapter" href="Lazy.html">
<link title="Lexing" rel="Chapter" href="Lexing.html">
<link title="List" rel="Chapter" href="List.html">
<link title="ListLabels" rel="Chapter" href="ListLabels.html">
<link title="Map" rel="Chapter" href="Map.html">
<link title="Marshal" rel="Chapter" href="Marshal.html">
<link title="MoreLabels" rel="Chapter" href="MoreLabels.html">
<link title="Mutex" rel="Chapter" href="Mutex.html">
<link title="Nativeint" rel="Chapter" href="Nativeint.html">
<link title="Obj" rel="Chapter" href="Obj.html">
<link title="Ocaml_operators" rel="Chapter" href="Ocaml_operators.html">
<link title="Oo" rel="Chapter" href="Oo.html">
<link title="Option" rel="Chapter" href="Option.html">
<link title="Parsing" rel="Chapter" href="Parsing.html">
<link title="Printexc" rel="Chapter" href="Printexc.html">
<link title="Printf" rel="Chapter" href="Printf.html">
<link title="Queue" rel="Chapter" href="Queue.html">
<link title="Random" rel="Chapter" href="Random.html">
<link title="Result" rel="Chapter" href="Result.html">
<link title="Scanf" rel="Chapter" href="Scanf.html">
<link title="Seq" rel="Chapter" href="Seq.html">
<link title="Set" rel="Chapter" href="Set.html">
<link title="Spacetime" rel="Chapter" href="Spacetime.html">
<link title="Stack" rel="Chapter" href="Stack.html">
<link title="StdLabels" rel="Chapter" href="StdLabels.html">
<link title="Stdlib" rel="Chapter" href="Stdlib.html">
<link title="Str" rel="Chapter" href="Str.html">
<link title="Stream" rel="Chapter" href="Stream.html">
<link title="String" rel="Chapter" href="String.html">
<link title="StringLabels" rel="Chapter" href="StringLabels.html">
<link title="Sys" rel="Chapter" href="Sys.html">
<link title="Thread" rel="Chapter" href="Thread.html">
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
<link title="Uchar" rel="Chapter" href="Uchar.html">
<link title="Unit" rel="Chapter" href="Unit.html">
<link title="Unix" rel="Chapter" href="Unix.html">
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
<link title="Weak" rel="Chapter" href="Weak.html"><link title="Iterators" rel="Section" href="#1_Iterators">
<link title="Iterators on two lists" rel="Section" href="#1_Iteratorsontwolists">
<link title="List scanning" rel="Section" href="#1_Listscanning">
<link title="List searching" rel="Section" href="#1_Listsearching">
<link title="Association lists" rel="Section" href="#1_Associationlists">
<link title="Lists of pairs" rel="Section" href="#1_Listsofpairs">
<link title="Sorting" rel="Section" href="#1_Sorting">
<link title="Iterators" rel="Section" href="#1_Iterators">
<title>Stdlib.List</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Stdlib.Lexing.html" title="Stdlib.Lexing">Previous</a>
&nbsp;<a class="up" href="Stdlib.html" title="Stdlib">Up</a>
&nbsp;<a class="post" href="Stdlib.ListLabels.html" title="Stdlib.ListLabels">Next</a>
</div>
<h1>Module <a href="type_Stdlib.List.html">Stdlib.List</a></h1>

<pre><span id="MODULEList"><span class="keyword">module</span> List</span>: <code class="type"><a href="List.html">List</a></code></pre><hr width="100%">

<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">'a</code> t</span> = <code class="type">'a list</code> = </pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTt.[]"><span class="constructor">[]</span></span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTt.::"><span class="constructor">::</span></span> <span class="keyword">of</span> <code class="type">'a * 'a list</code></code></td>

</tr></table>

<div class="info ">
<div class="info-desc">
<p>An alias for the type of lists.</p>
</div>
</div>


<pre><span id="VALlength"><span class="keyword">val</span> length</span> : <code class="type">'a list -> int</code></pre><div class="info ">
<div class="info-desc">
<p>Return the length (number of elements) of the given list.</p>
</div>
</div>

<pre><span id="VALcompare_lengths"><span class="keyword">val</span> compare_lengths</span> : <code class="type">'a list -> 'b list -> int</code></pre><div class="info ">
<div class="info-desc">
<p>Compare the lengths of two lists. <code class="code">compare_lengths&nbsp;l1&nbsp;l2</code> is
   equivalent to <code class="code">compare&nbsp;(length&nbsp;l1)&nbsp;(length&nbsp;l2)</code>, except that
   the computation stops after itering on the shortest list.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.05.0</li>
</ul>
</div>

<pre><span id="VALcompare_length_with"><span class="keyword">val</span> compare_length_with</span> : <code class="type">'a list -> int -> int</code></pre><div class="info ">
<div class="info-desc">
<p>Compare the length of a list to an integer. <code class="code">compare_length_with&nbsp;l&nbsp;n</code> is
   equivalent to <code class="code">compare&nbsp;(length&nbsp;l)&nbsp;n</code>, except that
   the computation stops after at most <code class="code">n</code> iterations on the list.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.05.0</li>
</ul>
</div>

<pre><span id="VALcons"><span class="keyword">val</span> cons</span> : <code class="type">'a -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">cons&nbsp;x&nbsp;xs</code> is <code class="code">x&nbsp;::&nbsp;xs</code></p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.03.0</li>
</ul>
</div>

<pre><span id="VALhd"><span class="keyword">val</span> hd</span> : <code class="type">'a list -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p>Return the first element of the given list.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Failure</code> if the list is empty.</li>
</ul>
</div>

<pre><span id="VALtl"><span class="keyword">val</span> tl</span> : <code class="type">'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Return the given list without its first element.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Failure</code> if the list is empty.</li>
</ul>
</div>

<pre><span id="VALnth"><span class="keyword">val</span> nth</span> : <code class="type">'a list -> int -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p>Return the <code class="code">n</code>-th element of the given list.
   The first element (head of the list) is at position 0.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b><ul><li><code>Failure</code> if the list is too short.</li>
<li><code>Invalid_argument</code> if <code class="code">n</code> is negative.</li>
</ul></li>
</ul>
</div>

<pre><span id="VALnth_opt"><span class="keyword">val</span> nth_opt</span> : <code class="type">'a list -> int -> 'a option</code></pre><div class="info ">
<div class="info-desc">
<p>Return the <code class="code">n</code>-th element of the given list.
    The first element (head of the list) is at position 0.
    Return <code class="code"><span class="constructor">None</span></code> if the list is too short.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.05</li>
<li><b>Raises</b> <code>Invalid_argument</code> if <code class="code">n</code> is negative.</li>
</ul>
</div>

<pre><span id="VALrev"><span class="keyword">val</span> rev</span> : <code class="type">'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>List reversal.</p>
</div>
</div>

<pre><span id="VALinit"><span class="keyword">val</span> init</span> : <code class="type">int -> (int -> 'a) -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.init&nbsp;len&nbsp;f</code> is <code class="code">[f&nbsp;0;&nbsp;f&nbsp;1;&nbsp;...;&nbsp;f&nbsp;(len-1)]</code>, evaluated left to right.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.06.0</li>
<li><b>Raises</b> <code>Invalid_argument</code> if len &lt; 0.</li>
</ul>
</div>

<pre><span id="VALappend"><span class="keyword">val</span> append</span> : <code class="type">'a list -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Concatenate two lists.  Same as the infix operator <code class="code">@</code>.
   Not tail-recursive (length of the first argument).</p>
</div>
</div>

<pre><span id="VALrev_append"><span class="keyword">val</span> rev_append</span> : <code class="type">'a list -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.rev_append&nbsp;l1&nbsp;l2</code> reverses <code class="code">l1</code> and concatenates it to <code class="code">l2</code>.
   This is equivalent to <a href="List.html#VALrev"><code class="code"><span class="constructor">List</span>.rev</code></a><code class="code">&nbsp;l1&nbsp;@&nbsp;l2</code>, but <code class="code">rev_append</code> is
   tail-recursive and more efficient.</p>
</div>
</div>

<pre><span id="VALconcat"><span class="keyword">val</span> concat</span> : <code class="type">'a list list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Concatenate a list of lists.  The elements of the argument are all
   concatenated together (in the same order) to give the result.
   Not tail-recursive
   (length of the argument + length of the longest sub-list).</p>
</div>
</div>

<pre><span id="VALflatten"><span class="keyword">val</span> flatten</span> : <code class="type">'a list list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>An alias for <code class="code">concat</code>.</p>
</div>
</div>
<h2 id="1_Iterators">Iterators</h2>
<pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">('a -> unit) -> 'a list -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.iter&nbsp;f&nbsp;[a1;&nbsp;...;&nbsp;an]</code> applies function <code class="code">f</code> in turn to
   <code class="code">a1;&nbsp;...;&nbsp;an</code>. It is equivalent to
   <code class="code"><span class="keyword">begin</span>&nbsp;f&nbsp;a1;&nbsp;f&nbsp;a2;&nbsp;...;&nbsp;f&nbsp;an;&nbsp;()&nbsp;<span class="keyword">end</span></code>.</p>
</div>
</div>

<pre><span id="VALiteri"><span class="keyword">val</span> iteri</span> : <code class="type">(int -> 'a -> unit) -> 'a list -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALiter"><code class="code"><span class="constructor">List</span>.iter</code></a>, but the function is applied to the index of
   the element as first argument (counting from 0), and the element
   itself as second argument.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.00.0</li>
</ul>
</div>

<pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">('a -> 'b) -> 'a list -> 'b list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.map&nbsp;f&nbsp;[a1;&nbsp;...;&nbsp;an]</code> applies function <code class="code">f</code> to <code class="code">a1,&nbsp;...,&nbsp;an</code>,
   and builds the list <code class="code">[f&nbsp;a1;&nbsp;...;&nbsp;f&nbsp;an]</code>
   with the results returned by <code class="code">f</code>.  Not tail-recursive.</p>
</div>
</div>

<pre><span id="VALmapi"><span class="keyword">val</span> mapi</span> : <code class="type">(int -> 'a -> 'b) -> 'a list -> 'b list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALmap"><code class="code"><span class="constructor">List</span>.map</code></a>, but the function is applied to the index of
   the element as first argument (counting from 0), and the element
   itself as second argument.  Not tail-recursive.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.00.0</li>
</ul>
</div>

<pre><span id="VALrev_map"><span class="keyword">val</span> rev_map</span> : <code class="type">('a -> 'b) -> 'a list -> 'b list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.rev_map&nbsp;f&nbsp;l</code> gives the same result as
   <a href="List.html#VALrev"><code class="code"><span class="constructor">List</span>.rev</code></a><code class="code">&nbsp;(</code><a href="List.html#VALmap"><code class="code"><span class="constructor">List</span>.map</code></a><code class="code">&nbsp;f&nbsp;l)</code>, but is tail-recursive and
   more efficient.</p>
</div>
</div>

<pre><span id="VALfilter_map"><span class="keyword">val</span> filter_map</span> : <code class="type">('a -> 'b option) -> 'a list -> 'b list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">filter_map&nbsp;f&nbsp;l</code> applies <code class="code">f</code> to every element of <code class="code">l</code>, filters
    out the <code class="code"><span class="constructor">None</span></code> elements and returns the list of the arguments of
    the <code class="code"><span class="constructor">Some</span></code> elements.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.08.0</li>
</ul>
</div>

<pre><span id="VALconcat_map"><span class="keyword">val</span> concat_map</span> : <code class="type">('a -> 'b list) -> 'a list -> 'b list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.concat_map&nbsp;f&nbsp;l</code> gives the same result as
    <a href="List.html#VALconcat"><code class="code"><span class="constructor">List</span>.concat</code></a><code class="code">&nbsp;(</code><a href="List.html#VALmap"><code class="code"><span class="constructor">List</span>.map</code></a><code class="code">&nbsp;f&nbsp;l)</code>. Tail-recursive.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.10.0</li>
</ul>
</div>

<pre><span id="VALfold_left_map"><span class="keyword">val</span> fold_left_map</span> : <code class="type">('a -> 'b -> 'a * 'c) -> 'a -> 'b list -> 'a * 'c list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">fold_left_map</code> is  a combination of <code class="code">fold_left</code> and <code class="code">map</code> that threads an
    accumulator through calls to <code class="code">f</code></p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.11.0</li>
</ul>
</div>

<pre><span id="VALfold_left"><span class="keyword">val</span> fold_left</span> : <code class="type">('a -> 'b -> 'a) -> 'a -> 'b list -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.fold_left&nbsp;f&nbsp;a&nbsp;[b1;&nbsp;...;&nbsp;bn]</code> is
   <code class="code">f&nbsp;(...&nbsp;(f&nbsp;(f&nbsp;a&nbsp;b1)&nbsp;b2)&nbsp;...)&nbsp;bn</code>.</p>
</div>
</div>

<pre><span id="VALfold_right"><span class="keyword">val</span> fold_right</span> : <code class="type">('a -> 'b -> 'b) -> 'a list -> 'b -> 'b</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.fold_right&nbsp;f&nbsp;[a1;&nbsp;...;&nbsp;an]&nbsp;b</code> is
   <code class="code">f&nbsp;a1&nbsp;(f&nbsp;a2&nbsp;(...&nbsp;(f&nbsp;an&nbsp;b)&nbsp;...))</code>.  Not tail-recursive.</p>
</div>
</div>
<h2 id="1_Iteratorsontwolists">Iterators on two lists</h2>
<pre><span id="VALiter2"><span class="keyword">val</span> iter2</span> : <code class="type">('a -> 'b -> unit) -> 'a list -> 'b list -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.iter2&nbsp;f&nbsp;[a1;&nbsp;...;&nbsp;an]&nbsp;[b1;&nbsp;...;&nbsp;bn]</code> calls in turn
   <code class="code">f&nbsp;a1&nbsp;b1;&nbsp;...;&nbsp;f&nbsp;an&nbsp;bn</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Invalid_argument</code> if the two lists are determined
   to have different lengths.</li>
</ul>
</div>

<pre><span id="VALmap2"><span class="keyword">val</span> map2</span> : <code class="type">('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.map2&nbsp;f&nbsp;[a1;&nbsp;...;&nbsp;an]&nbsp;[b1;&nbsp;...;&nbsp;bn]</code> is
   <code class="code">[f&nbsp;a1&nbsp;b1;&nbsp;...;&nbsp;f&nbsp;an&nbsp;bn]</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Invalid_argument</code> if the two lists are determined
   to have different lengths.  Not tail-recursive.</li>
</ul>
</div>

<pre><span id="VALrev_map2"><span class="keyword">val</span> rev_map2</span> : <code class="type">('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.rev_map2&nbsp;f&nbsp;l1&nbsp;l2</code> gives the same result as
   <a href="List.html#VALrev"><code class="code"><span class="constructor">List</span>.rev</code></a><code class="code">&nbsp;(</code><a href="List.html#VALmap2"><code class="code"><span class="constructor">List</span>.map2</code></a><code class="code">&nbsp;f&nbsp;l1&nbsp;l2)</code>, but is tail-recursive and
   more efficient.</p>
</div>
</div>

<pre><span id="VALfold_left2"><span class="keyword">val</span> fold_left2</span> : <code class="type">('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.fold_left2&nbsp;f&nbsp;a&nbsp;[b1;&nbsp;...;&nbsp;bn]&nbsp;[c1;&nbsp;...;&nbsp;cn]</code> is
   <code class="code">f&nbsp;(...&nbsp;(f&nbsp;(f&nbsp;a&nbsp;b1&nbsp;c1)&nbsp;b2&nbsp;c2)&nbsp;...)&nbsp;bn&nbsp;cn</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Invalid_argument</code> if the two lists are determined
   to have different lengths.</li>
</ul>
</div>

<pre><span id="VALfold_right2"><span class="keyword">val</span> fold_right2</span> : <code class="type">('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">List</span>.fold_right2&nbsp;f&nbsp;[a1;&nbsp;...;&nbsp;an]&nbsp;[b1;&nbsp;...;&nbsp;bn]&nbsp;c</code> is
   <code class="code">f&nbsp;a1&nbsp;b1&nbsp;(f&nbsp;a2&nbsp;b2&nbsp;(...&nbsp;(f&nbsp;an&nbsp;bn&nbsp;c)&nbsp;...))</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Invalid_argument</code> if the two lists are determined
   to have different lengths.  Not tail-recursive.</li>
</ul>
</div>
<h2 id="1_Listscanning">List scanning</h2>
<pre><span id="VALfor_all"><span class="keyword">val</span> for_all</span> : <code class="type">('a -> bool) -> 'a list -> bool</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">for_all&nbsp;p&nbsp;[a1;&nbsp;...;&nbsp;an]</code> checks if all elements of the list
   satisfy the predicate <code class="code">p</code>. That is, it returns
   <code class="code">(p&nbsp;a1)&nbsp;<span class="keywordsign">&amp;&amp;</span>&nbsp;(p&nbsp;a2)&nbsp;<span class="keywordsign">&amp;&amp;</span>&nbsp;...&nbsp;<span class="keywordsign">&amp;&amp;</span>&nbsp;(p&nbsp;an)</code> for a non-empty list and
   <code class="code"><span class="keyword">true</span></code> if the list is empty.</p>
</div>
</div>

<pre><span id="VALexists"><span class="keyword">val</span> exists</span> : <code class="type">('a -> bool) -> 'a list -> bool</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">exists&nbsp;p&nbsp;[a1;&nbsp;...;&nbsp;an]</code> checks if at least one element of
   the list satisfies the predicate <code class="code">p</code>. That is, it returns
   <code class="code">(p&nbsp;a1)&nbsp;<span class="keywordsign">||</span>&nbsp;(p&nbsp;a2)&nbsp;<span class="keywordsign">||</span>&nbsp;...&nbsp;<span class="keywordsign">||</span>&nbsp;(p&nbsp;an)</code> for a non-empty list and
   <code class="code"><span class="keyword">false</span></code> if the list is empty.</p>
</div>
</div>

<pre><span id="VALfor_all2"><span class="keyword">val</span> for_all2</span> : <code class="type">('a -> 'b -> bool) -> 'a list -> 'b list -> bool</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALfor_all"><code class="code"><span class="constructor">List</span>.for_all</code></a>, but for a two-argument predicate.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Invalid_argument</code> if the two lists are determined
   to have different lengths.</li>
</ul>
</div>

<pre><span id="VALexists2"><span class="keyword">val</span> exists2</span> : <code class="type">('a -> 'b -> bool) -> 'a list -> 'b list -> bool</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALexists"><code class="code"><span class="constructor">List</span>.exists</code></a>, but for a two-argument predicate.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Invalid_argument</code> if the two lists are determined
   to have different lengths.</li>
</ul>
</div>

<pre><span id="VALmem"><span class="keyword">val</span> mem</span> : <code class="type">'a -> 'a list -> bool</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">mem&nbsp;a&nbsp;l</code> is true if and only if <code class="code">a</code> is equal
   to an element of <code class="code">l</code>.</p>
</div>
</div>

<pre><span id="VALmemq"><span class="keyword">val</span> memq</span> : <code class="type">'a -> 'a list -> bool</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALmem"><code class="code"><span class="constructor">List</span>.mem</code></a>, but uses physical equality instead of structural
   equality to compare list elements.</p>
</div>
</div>
<h2 id="1_Listsearching">List searching</h2>
<pre><span id="VALfind"><span class="keyword">val</span> find</span> : <code class="type">('a -> bool) -> 'a list -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">find&nbsp;p&nbsp;l</code> returns the first element of the list <code class="code">l</code>
   that satisfies the predicate <code class="code">p</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Not_found</code> if there is no value that satisfies <code class="code">p</code> in the
   list <code class="code">l</code>.</li>
</ul>
</div>

<pre><span id="VALfind_opt"><span class="keyword">val</span> find_opt</span> : <code class="type">('a -> bool) -> 'a list -> 'a option</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">find_opt&nbsp;p&nbsp;l</code> returns the first element of the list <code class="code">l</code> that
    satisfies the predicate <code class="code">p</code>, or <code class="code"><span class="constructor">None</span></code> if there is no value that
    satisfies <code class="code">p</code> in the list <code class="code">l</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.05</li>
</ul>
</div>

<pre><span id="VALfind_map"><span class="keyword">val</span> find_map</span> : <code class="type">('a -> 'b option) -> 'a list -> 'b option</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">find_map&nbsp;f&nbsp;l</code> applies <code class="code">f</code> to the elements of <code class="code">l</code> in order,
    and returns the first result of the form <code class="code"><span class="constructor">Some</span>&nbsp;v</code>, or <code class="code"><span class="constructor">None</span></code>
    if none exist.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.10.0</li>
</ul>
</div>

<pre><span id="VALfilter"><span class="keyword">val</span> filter</span> : <code class="type">('a -> bool) -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">filter&nbsp;p&nbsp;l</code> returns all the elements of the list <code class="code">l</code>
   that satisfy the predicate <code class="code">p</code>.  The order of the elements
   in the input list is preserved.</p>
</div>
</div>

<pre><span id="VALfind_all"><span class="keyword">val</span> find_all</span> : <code class="type">('a -> bool) -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">find_all</code> is another name for <a href="List.html#VALfilter"><code class="code"><span class="constructor">List</span>.filter</code></a>.</p>
</div>
</div>

<pre><span id="VALfilteri"><span class="keyword">val</span> filteri</span> : <code class="type">(int -> 'a -> bool) -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALfilter"><code class="code"><span class="constructor">List</span>.filter</code></a>, but the predicate is applied to the index of
   the element as first argument (counting from 0), and the element
   itself as second argument.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.11.0</li>
</ul>
</div>

<pre><span id="VALpartition"><span class="keyword">val</span> partition</span> : <code class="type">('a -> bool) -> 'a list -> 'a list * 'a list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">partition&nbsp;p&nbsp;l</code> returns a pair of lists <code class="code">(l1,&nbsp;l2)</code>, where
   <code class="code">l1</code> is the list of all the elements of <code class="code">l</code> that
   satisfy the predicate <code class="code">p</code>, and <code class="code">l2</code> is the list of all the
   elements of <code class="code">l</code> that do not satisfy <code class="code">p</code>.
   The order of the elements in the input list is preserved.</p>
</div>
</div>
<h2 id="1_Associationlists">Association lists</h2>
<pre><span id="VALassoc"><span class="keyword">val</span> assoc</span> : <code class="type">'a -> ('a * 'b) list -> 'b</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">assoc&nbsp;a&nbsp;l</code> returns the value associated with key <code class="code">a</code> in the list of
   pairs <code class="code">l</code>. That is,
   <code class="code">assoc&nbsp;a&nbsp;[&nbsp;...;&nbsp;(a,b);&nbsp;...]&nbsp;=&nbsp;b</code>
   if <code class="code">(a,b)</code> is the leftmost binding of <code class="code">a</code> in list <code class="code">l</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Not_found</code> if there is no value associated with <code class="code">a</code> in the
   list <code class="code">l</code>.</li>
</ul>
</div>

<pre><span id="VALassoc_opt"><span class="keyword">val</span> assoc_opt</span> : <code class="type">'a -> ('a * 'b) list -> 'b option</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">assoc_opt&nbsp;a&nbsp;l</code> returns the value associated with key <code class="code">a</code> in the list of
   pairs <code class="code">l</code>. That is,
   <code class="code">assoc_opt&nbsp;a&nbsp;[&nbsp;...;&nbsp;(a,b);&nbsp;...]&nbsp;=&nbsp;b</code>
   if <code class="code">(a,b)</code> is the leftmost binding of <code class="code">a</code> in list <code class="code">l</code>.
   Returns <code class="code"><span class="constructor">None</span></code> if there is no value associated with <code class="code">a</code> in the
   list <code class="code">l</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.05</li>
</ul>
</div>

<pre><span id="VALassq"><span class="keyword">val</span> assq</span> : <code class="type">'a -> ('a * 'b) list -> 'b</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALassoc"><code class="code"><span class="constructor">List</span>.assoc</code></a>, but uses physical equality instead of structural
   equality to compare keys.</p>
</div>
</div>

<pre><span id="VALassq_opt"><span class="keyword">val</span> assq_opt</span> : <code class="type">'a -> ('a * 'b) list -> 'b option</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALassoc_opt"><code class="code"><span class="constructor">List</span>.assoc_opt</code></a>, but uses physical equality instead of structural
    equality to compare keys.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.05</li>
</ul>
</div>

<pre><span id="VALmem_assoc"><span class="keyword">val</span> mem_assoc</span> : <code class="type">'a -> ('a * 'b) list -> bool</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALassoc"><code class="code"><span class="constructor">List</span>.assoc</code></a>, but simply return true if a binding exists,
   and false if no bindings exist for the given key.</p>
</div>
</div>

<pre><span id="VALmem_assq"><span class="keyword">val</span> mem_assq</span> : <code class="type">'a -> ('a * 'b) list -> bool</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALmem_assoc"><code class="code"><span class="constructor">List</span>.mem_assoc</code></a>, but uses physical equality instead of
   structural equality to compare keys.</p>
</div>
</div>

<pre><span id="VALremove_assoc"><span class="keyword">val</span> remove_assoc</span> : <code class="type">'a -> ('a * 'b) list -> ('a * 'b) list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">remove_assoc&nbsp;a&nbsp;l</code> returns the list of
   pairs <code class="code">l</code> without the first pair with key <code class="code">a</code>, if any.
   Not tail-recursive.</p>
</div>
</div>

<pre><span id="VALremove_assq"><span class="keyword">val</span> remove_assq</span> : <code class="type">'a -> ('a * 'b) list -> ('a * 'b) list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALremove_assoc"><code class="code"><span class="constructor">List</span>.remove_assoc</code></a>, but uses physical equality instead
   of structural equality to compare keys.  Not tail-recursive.</p>
</div>
</div>
<h2 id="1_Listsofpairs">Lists of pairs</h2>
<pre><span id="VALsplit"><span class="keyword">val</span> split</span> : <code class="type">('a * 'b) list -> 'a list * 'b list</code></pre><div class="info ">
<div class="info-desc">
<p>Transform a list of pairs into a pair of lists:
   <code class="code">split&nbsp;[(a1,b1);&nbsp;...;&nbsp;(an,bn)]</code> is <code class="code">([a1;&nbsp;...;&nbsp;an],&nbsp;[b1;&nbsp;...;&nbsp;bn])</code>.
   Not tail-recursive.</p>
</div>
</div>

<pre><span id="VALcombine"><span class="keyword">val</span> combine</span> : <code class="type">'a list -> 'b list -> ('a * 'b) list</code></pre><div class="info ">
<div class="info-desc">
<p>Transform a pair of lists into a list of pairs:
   <code class="code">combine&nbsp;[a1;&nbsp;...;&nbsp;an]&nbsp;[b1;&nbsp;...;&nbsp;bn]</code> is
   <code class="code">[(a1,b1);&nbsp;...;&nbsp;(an,bn)]</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Invalid_argument</code> if the two lists
   have different lengths.  Not tail-recursive.</li>
</ul>
</div>
<h2 id="1_Sorting">Sorting</h2>
<pre><span id="VALsort"><span class="keyword">val</span> sort</span> : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Sort a list in increasing order according to a comparison
   function.  The comparison function must return 0 if its arguments
   compare as equal, a positive integer if the first is greater,
   and a negative integer if the first is smaller (see Array.sort for
   a complete specification).  For example,
   <a href="Stdlib.html#VALcompare"><code class="code">compare</code></a> is a suitable comparison function.
   The resulting list is sorted in increasing order.
   <code class="code"><span class="constructor">List</span>.sort</code> is guaranteed to run in constant heap space
   (in addition to the size of the result list) and logarithmic
   stack space.</p>

<p>The current implementation uses Merge Sort. It runs in constant
   heap space and logarithmic stack space.</p>
</div>
</div>

<pre><span id="VALstable_sort"><span class="keyword">val</span> stable_sort</span> : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALsort"><code class="code"><span class="constructor">List</span>.sort</code></a>, but the sorting algorithm is guaranteed to
   be stable (i.e. elements that compare equal are kept in their
   original order) .</p>

<p>The current implementation uses Merge Sort. It runs in constant
   heap space and logarithmic stack space.</p>
</div>
</div>

<pre><span id="VALfast_sort"><span class="keyword">val</span> fast_sort</span> : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALsort"><code class="code"><span class="constructor">List</span>.sort</code></a> or <a href="List.html#VALstable_sort"><code class="code"><span class="constructor">List</span>.stable_sort</code></a>, whichever is faster
    on typical input.</p>
</div>
</div>

<pre><span id="VALsort_uniq"><span class="keyword">val</span> sort_uniq</span> : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="List.html#VALsort"><code class="code"><span class="constructor">List</span>.sort</code></a>, but also remove duplicates.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02.0</li>
</ul>
</div>

<pre><span id="VALmerge"><span class="keyword">val</span> merge</span> : <code class="type">('a -> 'a -> int) -> 'a list -> 'a list -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Merge two lists:
    Assuming that <code class="code">l1</code> and <code class="code">l2</code> are sorted according to the
    comparison function <code class="code">cmp</code>, <code class="code">merge&nbsp;cmp&nbsp;l1&nbsp;l2</code> will return a
    sorted list containing all the elements of <code class="code">l1</code> and <code class="code">l2</code>.
    If several elements compare equal, the elements of <code class="code">l1</code> will be
    before the elements of <code class="code">l2</code>.
    Not tail-recursive (sum of the lengths of the arguments).</p>
</div>
</div>
<h2 id="1_Iterators">Iterators</h2>
<pre><span id="VALto_seq"><span class="keyword">val</span> to_seq</span> : <code class="type">'a list -> 'a <a href="Seq.html#TYPEt">Seq.t</a></code></pre><div class="info ">
<div class="info-desc">
<p>Iterate on the list</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.07</li>
</ul>
</div>

<pre><span id="VALof_seq"><span class="keyword">val</span> of_seq</span> : <code class="type">'a <a href="Seq.html#TYPEt">Seq.t</a> -> 'a list</code></pre><div class="info ">
<div class="info-desc">
<p>Create a list from the iterator</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.07</li>
</ul>
</div>
</body></html>