Misc.Stdlib.List(3) OCaml library Misc.Stdlib.List(3)

# [NAME](#NAME)

Misc.Stdlib.List - Extensions to the List module

# [Module](#Module)

Module Misc.Stdlib.List

# [Documentation](#Documentation)

Module **List**  
: **sig end**

## [Extensions to the List module](#Extensions_to_the_List_module)

*type* **'a** *t* = **'a list**

*val compare* : **('a -&gt; 'a -&gt; int) -&gt; 'a t -&gt; 'a t -&gt; int**

The lexicographic order supported by the provided order. There is no constraint on the relative lengths of the lists.

*val equal* : **('a -&gt; 'a -&gt; bool) -&gt; 'a t -&gt; 'a t -&gt; bool**

Returns **true** if and only if the given lists have the same length and content with respect to the given equality function.

*val some\_if\_all\_elements\_are\_some* : **'a option t -&gt; 'a t option**

If all elements of the given list are **Some \_** then **Some xs** is returned with the **xs** being the contents of those **Some** s, with order preserved. Otherwise return **None** .

*val map2\_prefix* : **('a -&gt; 'b -&gt; 'c) -&gt;** **'a t -&gt;** **'b t -&gt; 'c t * 'b t**

**let r1, r2 = map2\_prefix f l1 l2** If **l1** is of length n and **l2 = h2 @ t2** with h2 of length n, r1 is **List.map2 f l1 h1** and r2 is t2.

*val iteri2* : **(int -&gt; 'a -&gt; 'b -&gt; unit) -&gt; 'a list -&gt; 'b list -&gt; unit**

Same as **List.iter2** , but the function is applied to the index of the element as first argument (counting from 0)

*val split\_at* : **int -&gt; 'a t -&gt; 'a t * 'a t**

**split\_at n l** returns the pair **before, after** where **before** is the **n** first elements of **l** and **after** the remaining ones. If **l** has less than **n** elements, raises Invalid\_argument.

*val chunks\_of* : **int -&gt; 'a t -&gt; 'a t t**

**chunks\_of n t** returns a list of nonempty lists whose concatenation is equal to the original list. Every list has **n** elements, except for possibly the last list, which may have fewer. **chunks\_of** raises if **n &lt;= 0** .

*val is\_prefix* : **equal:('a -&gt; 'a -&gt; bool) -&gt; 'a list -&gt; of\_:'a list -&gt; bool**

Returns **true** if and only if the given list, with respect to the given equality function on list members, is a prefix of the list **of\_** .

*type* **'a** *longest\_common\_prefix\_result* = private {  
longest\_common\_prefix : **'a list** ;  
first\_without\_longest\_common\_prefix : **'a list** ;  
second\_without\_longest\_common\_prefix : **'a list** ;  
}

*val find\_and\_chop\_longest\_common\_prefix* : **equal:('a -&gt; 'a -&gt; bool) -&gt;** **first:'a list -&gt;** **second:'a list -&gt; 'a longest\_common\_prefix\_result**

Returns the longest list that, with respect to the provided equality function, is a prefix of both of the given lists. The input lists, each with such longest common prefix removed, are also returned.

2026-10-01 OCamldoc

---

Document: Misc.Stdlib.List(3o) from ocaml 5.5.1-r1 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
