@@ -90,8 +90,29 @@ switch List.headExn(list{}) {
9090- Raises an Error if list is empty.
9191
9292*/
93+ @deprecated ("Use `headOrThrow` instead" )
9394let headExn : list <'a > => 'a
9495
96+ /**
97+ `headOrThrow(list)` same as [`head`](#head).
98+
99+ ## Examples
100+
101+ ```rescript
102+ List.headOrThrow(list{1, 2, 3})->assertEqual(1)
103+
104+ switch List.headOrThrow(list{}) {
105+ | exception Not_found => assert(true)
106+ | _ => assert(false)
107+ }
108+ ```
109+
110+ ## Exceptions
111+
112+ - Raises an Error if list is empty.
113+ */
114+ let headOrThrow : list <'a > => 'a
115+
95116/**
96117`tail(list)` returns `None` if `list` is empty, otherwise it returns `Some(tail)`
97118where `tail` is everything except the first element of `list`.
@@ -124,8 +145,25 @@ switch List.tailExn(list{}) {
124145
125146- Raises an Error if list is empty.
126147*/
148+ @deprecated ("Use `tailOrThrow` instead" )
127149let tailExn : list <'a > => list <'a >
128150
151+ /**
152+ `tailOrThrow(list)` same as [`tail`](#tail).
153+ Raises an Error if list is empty.
154+
155+ ## Examples
156+ ```res
157+ List.tailOrThrow(list{1, 2, 3})->assertEqual(list{2, 3})
158+
159+ switch List.tailOrThrow(list{}) {
160+ | _ => Console.log("never happens")
161+ | exception _ => Console.log("error")
162+ }
163+ ```
164+ */
165+ let tailOrThrow : list <'a > => list <'a >
166+
129167/**
130168`add(list, value)` adds a `value` to the beginning of list `list`.
131169
@@ -177,8 +215,26 @@ switch abc->List.getExn(4) {
177215
178216- Raises an Error if `index` is larger than the length of list.
179217*/
218+ @deprecated ("Use `getOrThrow` instead" )
180219let getExn : (list <'a >, int ) => 'a
181220
221+ /**
222+ `getOrThrow(list, index)` same as [`get`](#get).
223+ Raises an Error if `index` is larger than the length of list.
224+
225+ ## Examples
226+ ```res
227+ let abc = list{"A", "B", "C"}
228+ abc->List.getOrThrow(1)->assertEqual("B")
229+
230+ switch abc->List.getOrThrow(4) {
231+ | _ => Console.log("never happens")
232+ | exception _ => Console.log("error")
233+ }
234+ ```
235+ */
236+ let getOrThrow : (list <'a >, int ) => 'a
237+
182238/**
183239`make(length, value)` returns a list of length `length` with each element filled
184240with `value`. Returns an empty list if `value` is negative.
0 commit comments